From d6788595aa64dbb8fe55703cfec1b9368fe3c245 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 12 Mar 2025 14:07:34 +0100 Subject: [PATCH v21.2 2/4] Add get_opfamily_member_for_cmptype() --- src/backend/utils/cache/lsyscache.c | 20 ++++++++++++++++++++ src/include/utils/lsyscache.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 9f7c0315052..2151d8d0915 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -184,6 +184,26 @@ get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, return result; } +/* + * get_opfamily_member_for_cmptype + * Get the OID of the operator that implements the specified comparison + * type with the specified datatypes for the specified opfamily. + * + * Returns InvalidOid if there is no pg_amop entry for the given keys. + */ +Oid +get_opfamily_member_for_cmptype(Oid opfamily, Oid lefttype, Oid righttype, + CompareType cmptype) +{ + Oid opmethod; + StrategyNumber strategy; + + opmethod = get_opfamily_method(opfamily); + strategy = IndexAmTranslateCompareType(cmptype, opmethod, opfamily, false); + + return get_opfamily_member(opfamily, lefttype, righttype, strategy); +} + /* * get_ordering_op_properties * Given the OID of an ordering operator (a btree "<" or ">" operator), diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 271eac2f0e1..d42380a0d46 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -14,6 +14,7 @@ #define LSYSCACHE_H #include "access/attnum.h" +#include "access/cmptype.h" #include "access/htup.h" #include "nodes/pg_list.h" @@ -74,6 +75,8 @@ extern void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op, Oid *righttype); extern Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy); +extern Oid get_opfamily_member_for_cmptype(Oid opfamily, Oid lefttype, Oid righttype, + CompareType cmptype); extern bool get_ordering_op_properties(Oid opno, Oid *opfamily, Oid *opcintype, int16 *strategy); extern Oid get_equality_op_for_ordering_op(Oid opno, bool *reverse); -- 2.48.1