From 630f9a43cece93cb4a5c243b30e34abce6a89514 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 15 Jan 2025 11:28:39 +0100 Subject: Change gist stratnum function to use CompareType This changes commit 7406ab623fe in that the gist strategy number mapping support function is changed to use the CompareType enum as input, instead of the "well-known" RT*StrategyNumber strategy numbers. This is a bit cleaner, since you are not dealing with two sets of strategy numbers. Also, this will enable us to subsume this system into a more general system of using CompareType to define operator semantics across index methods. Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com --- src/backend/access/gist/gistutil.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'src/backend/access/gist/gistutil.c') diff --git a/src/backend/access/gist/gistutil.c b/src/backend/access/gist/gistutil.c index a2fcfbe4807..48db718b904 100644 --- a/src/backend/access/gist/gistutil.c +++ b/src/backend/access/gist/gistutil.c @@ -1058,27 +1058,44 @@ gistGetFakeLSN(Relation rel) } /* - * Returns the same number that was received. - * - * This is for GiST opclasses that use the RT*StrategyNumber constants. + * This is a stratnum support function for GiST opclasses that use the + * RT*StrategyNumber constants. */ Datum -gist_stratnum_identity(PG_FUNCTION_ARGS) +gist_stratnum_common(PG_FUNCTION_ARGS) { - StrategyNumber strat = PG_GETARG_UINT16(0); + CompareType cmptype = PG_GETARG_INT32(0); - PG_RETURN_UINT16(strat); + switch (cmptype) + { + case COMPARE_EQ: + PG_RETURN_UINT16(RTEqualStrategyNumber); + case COMPARE_LT: + PG_RETURN_UINT16(RTLessStrategyNumber); + case COMPARE_LE: + PG_RETURN_UINT16(RTLessEqualStrategyNumber); + case COMPARE_GT: + PG_RETURN_UINT16(RTGreaterStrategyNumber); + case COMPARE_GE: + PG_RETURN_UINT16(RTGreaterEqualStrategyNumber); + case COMPARE_OVERLAP: + PG_RETURN_UINT16(RTOverlapStrategyNumber); + case COMPARE_CONTAINED_BY: + PG_RETURN_UINT16(RTContainedByStrategyNumber); + default: + PG_RETURN_UINT16(InvalidStrategy); + } } /* - * Returns the opclass's private stratnum used for the given strategy. + * Returns the opclass's private stratnum used for the given compare type. * * Calls the opclass's GIST_STRATNUM_PROC support function, if any, * and returns the result. * Returns InvalidStrategy if the function is not defined. */ StrategyNumber -GistTranslateStratnum(Oid opclass, StrategyNumber strat) +GistTranslateStratnum(Oid opclass, CompareType cmptype) { Oid opfamily; Oid opcintype; @@ -1095,6 +1112,6 @@ GistTranslateStratnum(Oid opclass, StrategyNumber strat) return InvalidStrategy; /* Ask the translation function */ - result = OidFunctionCall1Coll(funcid, InvalidOid, UInt16GetDatum(strat)); + result = OidFunctionCall1Coll(funcid, InvalidOid, Int32GetDatum(cmptype)); return DatumGetUInt16(result); } -- cgit v1.2.3