Skip to content

Commit 7317e64

Browse files
committed
Add some opfamily support functions to lsyscache.c
Add get_opfamily_method() and get_opfamily_member_for_cmptype() in lsyscache.c. No callers yet, but we'll add some soon. This is part of generalizing some parts of the code away from having btree hardcoded and use CompareType instead. Author: Mark Dilger <mark.dilger@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
1 parent 122a9af commit 7317e64

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/backend/utils/cache/lsyscache.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype,
184184
return result;
185185
}
186186

187+
/*
188+
* get_opfamily_member_for_cmptype
189+
* Get the OID of the operator that implements the specified comparison
190+
* type with the specified datatypes for the specified opfamily.
191+
*
192+
* Returns InvalidOid if there is no mapping for the comparison type or no
193+
* pg_amop entry for the given keys.
194+
*/
195+
Oid
196+
get_opfamily_member_for_cmptype(Oid opfamily, Oid lefttype, Oid righttype,
197+
CompareType cmptype)
198+
{
199+
Oid opmethod;
200+
StrategyNumber strategy;
201+
202+
opmethod = get_opfamily_method(opfamily);
203+
strategy = IndexAmTranslateCompareType(cmptype, opmethod, opfamily, true);
204+
if (!strategy)
205+
return InvalidOid;
206+
return get_opfamily_member(opfamily, lefttype, righttype, strategy);
207+
}
208+
187209
/*
188210
* get_ordering_op_properties
189211
* Given the OID of an ordering operator (a btree "<" or ">" operator),
@@ -1288,6 +1310,28 @@ get_opclass_method(Oid opclass)
12881310

12891311
/* ---------- OPFAMILY CACHE ---------- */
12901312

1313+
/*
1314+
* get_opfamily_method
1315+
*
1316+
* Returns the OID of the index access method the opfamily is for.
1317+
*/
1318+
Oid
1319+
get_opfamily_method(Oid opfid)
1320+
{
1321+
HeapTuple tp;
1322+
Form_pg_opfamily opfform;
1323+
Oid result;
1324+
1325+
tp = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfid));
1326+
if (!HeapTupleIsValid(tp))
1327+
elog(ERROR, "cache lookup failed for operator family %u", opfid);
1328+
opfform = (Form_pg_opfamily) GETSTRUCT(tp);
1329+
1330+
result = opfform->opfmethod;
1331+
ReleaseSysCache(tp);
1332+
return result;
1333+
}
1334+
12911335
char *
12921336
get_opfamily_name(Oid opfid, bool missing_ok)
12931337
{

src/include/utils/lsyscache.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LSYSCACHE_H
1515

1616
#include "access/attnum.h"
17+
#include "access/cmptype.h"
1718
#include "access/htup.h"
1819
#include "nodes/pg_list.h"
1920

@@ -74,6 +75,8 @@ extern void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op,
7475
Oid *righttype);
7576
extern Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype,
7677
int16 strategy);
78+
extern Oid get_opfamily_member_for_cmptype(Oid opfamily, Oid lefttype, Oid righttype,
79+
CompareType cmptype);
7780
extern bool get_ordering_op_properties(Oid opno,
7881
Oid *opfamily, Oid *opcintype, int16 *strategy);
7982
extern Oid get_equality_op_for_ordering_op(Oid opno, bool *reverse);
@@ -108,6 +111,7 @@ extern Oid get_opclass_input_type(Oid opclass);
108111
extern bool get_opclass_opfamily_and_input_type(Oid opclass,
109112
Oid *opfamily, Oid *opcintype);
110113
extern Oid get_opclass_method(Oid opclass);
114+
extern Oid get_opfamily_method(Oid opfid);
111115
extern char *get_opfamily_name(Oid opfid, bool missing_ok);
112116
extern RegProcedure get_opcode(Oid opno);
113117
extern char *get_opname(Oid opno);

0 commit comments

Comments
 (0)