/* * FindDefaultConversion * * Find "default" conversion proc by for_encoding and to_encoding in the * given namespace. * * If found, returns the procedure's oid, otherwise InvalidOid. Note that * you get the procedure's OID not the conversion's OID! */ Oid FindDefaultConversion(Oid name_space, int32 for_encoding, int32 to_encoding) { CatCList *catlist; HeapTuple tuple; Form_pg_conversion body; Oid proc = InvalidOid; int i; catlist = SearchSysCacheList3(CONDEFAULT, ObjectIdGetDatum(name_space), Int32GetDatum(for_encoding), Int32GetDatum(to_encoding)); for (i = 0; i < catlist->n_members; i++) { tuple = &catlist->members[i]->tuple; body = (Form_pg_conversion) GETSTRUCT(tuple); if (body->condefault) { proc = body->conproc; break; } } ReleaseSysCacheList(catlist); return proc; }
/* * get_op_hash_function * Get the OID of the datatype-specific hash function associated with * a hashable equality operator. * * Returns InvalidOid if no hash function can be found. (This indicates * that the operator should not have been marked oprcanhash.) */ Oid get_op_hash_function(Oid opno) { CatCList *catlist; int i; Oid opclass = InvalidOid; /* * Search pg_amop to see if the target operator is registered as the "=" * operator of any hash opclass. If the operator is registered in * multiple opclasses, assume we can use the associated hash function from * any one. */ catlist = SearchSysCacheList(AMOPOPID, 1, ObjectIdGetDatum(opno), 0, 0, 0); for (i = 0; i < catlist->n_members; i++) { HeapTuple tuple = &catlist->members[i]->tuple; Form_pg_amop aform = (Form_pg_amop) GETSTRUCT(tuple); if (aform->amopstrategy == HTEqualStrategyNumber && opclass_is_hash(aform->amopclaid)) { opclass = aform->amopclaid; break; } } ReleaseSysCacheList(catlist); if (OidIsValid(opclass)) { /* Found a suitable opclass, get its default hash support function */ return get_opclass_proc(opclass, InvalidOid, HASHPROC); } /* Didn't find a match... */ return InvalidOid; }
/* * Gets list of publication oids for a relation oid. */ List * GetRelationPublications(Oid relid) { List *result = NIL; CatCList *pubrellist; int i; /* Find all publications associated with the relation. */ pubrellist = SearchSysCacheList1(PUBLICATIONRELMAP, ObjectIdGetDatum(relid)); for (i = 0; i < pubrellist->n_members; i++) { HeapTuple tup = &pubrellist->members[i]->tuple; Oid pubid = ((Form_pg_publication_rel) GETSTRUCT(tup))->prpubid; result = lappend_oid(result, pubid); } ReleaseSysCacheList(pubrellist); return result; }
/* * get_op_btree_interpretation * Given an operator's OID, find out which btree opclasses it belongs to, * and what strategy number it has within each one. The results are * returned as an OID list and a parallel integer list. * * In addition to the normal btree operators, we consider a <> operator to be * a "member" of an opclass if its negator is the opclass' equality operator. * ROWCOMPARE_NE is returned as the strategy number for this case. */ void get_op_btree_interpretation(Oid opno, List **opclasses, List **opstrats) { Oid lefttype, righttype; CatCList *catlist; bool op_negated; int i; *opclasses = NIL; *opstrats = NIL; /* * Get the nominal left-hand input type of the operator; we will ignore * opclasses that don't have that as the expected input datatype. This is * a kluge to avoid being confused by binary-compatible opclasses (such as * text_ops and varchar_ops, which share the same operators). */ op_input_types(opno, &lefttype, &righttype); Assert(OidIsValid(lefttype)); /* * Find all the pg_amop entries containing the operator. */ catlist = SearchSysCacheList(AMOPOPID, 1, ObjectIdGetDatum(opno), 0, 0, 0); /* * If we can't find any opclass containing the op, perhaps it is a <> * operator. See if it has a negator that is in an opclass. */ op_negated = false; if (catlist->n_members == 0) { Oid op_negator = get_negator(opno); if (OidIsValid(op_negator)) { op_negated = true; ReleaseSysCacheList(catlist); catlist = SearchSysCacheList(AMOPOPID, 1, ObjectIdGetDatum(op_negator), 0, 0, 0); } } /* Now search the opclasses */ for (i = 0; i < catlist->n_members; i++) { HeapTuple op_tuple = &catlist->members[i]->tuple; Form_pg_amop op_form = (Form_pg_amop) GETSTRUCT(op_tuple); Oid opclass_id; StrategyNumber op_strategy; opclass_id = op_form->amopclaid; /* must be btree */ if (!opclass_is_btree(opclass_id)) continue; /* must match operator input type exactly */ if (get_opclass_input_type(opclass_id) != lefttype) continue; /* Get the operator's btree strategy number */ op_strategy = (StrategyNumber) op_form->amopstrategy; Assert(op_strategy >= 1 && op_strategy <= 5); if (op_negated) { /* Only consider negators that are = */ if (op_strategy != BTEqualStrategyNumber) continue; op_strategy = ROWCOMPARE_NE; } *opclasses = lappend_oid(*opclasses, opclass_id); *opstrats = lappend_int(*opstrats, op_strategy); } ReleaseSysCacheList(catlist); }