aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/index
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2025-02-02 10:26:04 +0100
committerPeter Eisentraut <peter@eisentraut.org>2025-02-02 10:26:04 +0100
commitc09e5a6a01659a66dd84f3e745694999d3414ddd (patch)
tree85c7b89405656557e73360aa65216baf91f01a5b /src/backend/access/index
parent119fc30dd5bd918819b864107ddc8baac51f4d22 (diff)
downloadpostgresql-c09e5a6a01659a66dd84f3e745694999d3414ddd.tar.gz
postgresql-c09e5a6a01659a66dd84f3e745694999d3414ddd.zip
Convert strategies to and from compare types
For each Index AM, provide a mapping between operator strategies and the system-wide generic concept of a comparison type. For example, for btree, BTLessStrategyNumber maps to and from COMPARE_LT. Numerous places in the planner and executor think directly in terms of btree strategy numbers (and a few in terms of hash strategy numbers.) These should be converted over subsequent commits to think in terms of CompareType instead. (This commit doesn't make any use of this API yet.) Author: Mark Dilger <mark.dilger@enterprisedb.com> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
Diffstat (limited to 'src/backend/access/index')
-rw-r--r--src/backend/access/index/amapi.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/backend/access/index/amapi.c b/src/backend/access/index/amapi.c
index 3522bcaa401..5f53f49ec32 100644
--- a/src/backend/access/index/amapi.c
+++ b/src/backend/access/index/amapi.c
@@ -108,6 +108,56 @@ GetIndexAmRoutineByAmId(Oid amoid, bool noerror)
/*
+ * IndexAmTranslateStrategy - given an access method and strategy, get the
+ * corresponding compare type.
+ *
+ * If missing_ok is false, throw an error if no compare type is found. If
+ * true, just return COMPARE_INVALID.
+ */
+CompareType
+IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, Oid opcintype, bool missing_ok)
+{
+ CompareType result;
+ IndexAmRoutine *amroutine;
+
+ amroutine = GetIndexAmRoutineByAmId(amoid, false);
+ if (amroutine->amtranslatestrategy)
+ result = amroutine->amtranslatestrategy(strategy, opfamily, opcintype);
+ else
+ result = COMPARE_INVALID;
+
+ if (!missing_ok && result == COMPARE_INVALID)
+ elog(ERROR, "could not translate strategy number %d for index AM %u", strategy, amoid);
+
+ return result;
+}
+
+/*
+ * IndexAmTranslateCompareType - given an access method and compare type, get
+ * the corresponding strategy number.
+ *
+ * If missing_ok is false, throw an error if no strategy is found correlating
+ * to the given cmptype. If true, just return InvalidStrategy.
+ */
+StrategyNumber
+IndexAmTranslateCompareType(CompareType cmptype, Oid amoid, Oid opfamily, Oid opcintype, bool missing_ok)
+{
+ StrategyNumber result;
+ IndexAmRoutine *amroutine;
+
+ amroutine = GetIndexAmRoutineByAmId(amoid, false);
+ if (amroutine->amtranslatecmptype)
+ result = amroutine->amtranslatecmptype(cmptype, opfamily, opcintype);
+ else
+ result = InvalidStrategy;
+
+ if (!missing_ok && result == InvalidStrategy)
+ elog(ERROR, "could not translate compare type %u for index AM %u", cmptype, amoid);
+
+ return result;
+}
+
+/*
* Ask appropriate access method to validate the specified opclass.
*/
Datum