+/*
+ * get_opclass_member
+ * Get the OID of the operator that implements the specified strategy
+ * for the specified opclass.
+ *
+ * Returns InvalidOid if there is no pg_amop entry for the given keys.
+ */
+Oid
+get_opclass_member(Oid opclass, int16 strategy)
+{
+ HeapTuple tp;
+ Form_pg_amop amop_tup;
+ Oid result;
+
+ tp = SearchSysCache(AMOPSTRATEGY,
+ ObjectIdGetDatum(opclass),
+ Int16GetDatum(strategy),
+ 0, 0);
+ if (!HeapTupleIsValid(tp))
+ return InvalidOid;
+ amop_tup = (Form_pg_amop) GETSTRUCT(tp);
+ result = amop_tup->amopopr;
+ ReleaseSysCache(tp);
+ return result;
+}
+
+/*
+ * 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 hash support function */
+ return get_opclass_proc(opclass, HASHPROC);
+ }
+
+ /* Didn't find a match... */
+ return InvalidOid;
+}
+
+
+/* ---------- AMPROC CACHES ---------- */
+
+/*
+ * get_opclass_proc
+ * Get the OID of the specified support function
+ * for the specified opclass.
+ *
+ * Returns InvalidOid if there is no pg_amproc entry for the given keys.
+ */
+Oid
+get_opclass_proc(Oid opclass, int16 procnum)
+{
+ HeapTuple tp;
+ Form_pg_amproc amproc_tup;
+ RegProcedure result;
+
+ tp = SearchSysCache(AMPROCNUM,
+ ObjectIdGetDatum(opclass),
+ Int16GetDatum(procnum),
+ 0, 0);
+ if (!HeapTupleIsValid(tp))
+ return InvalidOid;
+ amproc_tup = (Form_pg_amproc) GETSTRUCT(tp);
+ result = amproc_tup->amproc;
+ ReleaseSysCache(tp);
+ return result;
+}
+
+