diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/access/brin/brin.c | 2 | ||||
-rw-r--r-- | src/backend/access/gist/gist.c | 2 | ||||
-rw-r--r-- | src/backend/access/hash/hash.c | 19 | ||||
-rw-r--r-- | src/backend/access/index/amapi.c | 50 | ||||
-rw-r--r-- | src/backend/access/nbtree/nbtree.c | 43 | ||||
-rw-r--r-- | src/backend/access/spgist/spgutils.c | 2 |
6 files changed, 118 insertions, 0 deletions
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c index 4289142e20b..ccf824bbdb2 100644 --- a/src/backend/access/brin/brin.c +++ b/src/backend/access/brin/brin.c @@ -298,6 +298,8 @@ brinhandler(PG_FUNCTION_ARGS) amroutine->amestimateparallelscan = NULL; amroutine->aminitparallelscan = NULL; amroutine->amparallelrescan = NULL; + amroutine->amtranslatestrategy = NULL; + amroutine->amtranslatecmptype = NULL; PG_RETURN_POINTER(amroutine); } diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c index b6bc75b44e3..70f8086db7b 100644 --- a/src/backend/access/gist/gist.c +++ b/src/backend/access/gist/gist.c @@ -107,6 +107,8 @@ gisthandler(PG_FUNCTION_ARGS) amroutine->amestimateparallelscan = NULL; amroutine->aminitparallelscan = NULL; amroutine->amparallelrescan = NULL; + amroutine->amtranslatestrategy = NULL; + amroutine->amtranslatecmptype = NULL; PG_RETURN_POINTER(amroutine); } diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c index df8409ab233..63b568e7f24 100644 --- a/src/backend/access/hash/hash.c +++ b/src/backend/access/hash/hash.c @@ -21,6 +21,7 @@ #include "access/hash.h" #include "access/hash_xlog.h" #include "access/relscan.h" +#include "access/stratnum.h" #include "access/tableam.h" #include "access/xloginsert.h" #include "commands/progress.h" @@ -105,6 +106,8 @@ hashhandler(PG_FUNCTION_ARGS) amroutine->amestimateparallelscan = NULL; amroutine->aminitparallelscan = NULL; amroutine->amparallelrescan = NULL; + amroutine->amtranslatestrategy = hashtranslatestrategy; + amroutine->amtranslatecmptype = hashtranslatecmptype; PG_RETURN_POINTER(amroutine); } @@ -922,3 +925,19 @@ hashbucketcleanup(Relation rel, Bucket cur_bucket, Buffer bucket_buf, else LockBuffer(bucket_buf, BUFFER_LOCK_UNLOCK); } + +CompareType +hashtranslatestrategy(StrategyNumber strategy, Oid opfamily, Oid opcintype) +{ + if (strategy == HTEqualStrategyNumber) + return COMPARE_EQ; + return COMPARE_INVALID; +} + +StrategyNumber +hashtranslatecmptype(CompareType cmptype, Oid opfamily, Oid opcintype) +{ + if (cmptype == COMPARE_EQ) + return HTEqualStrategyNumber; + return InvalidStrategy; +} 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 diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c index 3d617f168f5..971405e89af 100644 --- a/src/backend/access/nbtree/nbtree.c +++ b/src/backend/access/nbtree/nbtree.c @@ -20,6 +20,7 @@ #include "access/nbtree.h" #include "access/relscan.h" +#include "access/stratnum.h" #include "commands/progress.h" #include "commands/vacuum.h" #include "nodes/execnodes.h" @@ -148,6 +149,8 @@ bthandler(PG_FUNCTION_ARGS) amroutine->amestimateparallelscan = btestimateparallelscan; amroutine->aminitparallelscan = btinitparallelscan; amroutine->amparallelrescan = btparallelrescan; + amroutine->amtranslatestrategy = bttranslatestrategy; + amroutine->amtranslatecmptype = bttranslatecmptype; PG_RETURN_POINTER(amroutine); } @@ -1508,3 +1511,43 @@ btgettreeheight(Relation rel) { return _bt_getrootheight(rel); } + +CompareType +bttranslatestrategy(StrategyNumber strategy, Oid opfamily, Oid opcintype) +{ + switch (strategy) + { + case BTLessStrategyNumber: + return COMPARE_LT; + case BTLessEqualStrategyNumber: + return COMPARE_LE; + case BTEqualStrategyNumber: + return COMPARE_EQ; + case BTGreaterEqualStrategyNumber: + return COMPARE_GE; + case BTGreaterStrategyNumber: + return COMPARE_GT; + default: + return COMPARE_INVALID; + } +} + +StrategyNumber +bttranslatecmptype(CompareType cmptype, Oid opfamily, Oid opcintype) +{ + switch (cmptype) + { + case COMPARE_LT: + return BTLessStrategyNumber; + case COMPARE_LE: + return BTLessEqualStrategyNumber; + case COMPARE_EQ: + return BTEqualStrategyNumber; + case COMPARE_GE: + return BTGreaterEqualStrategyNumber; + case COMPARE_GT: + return BTGreaterStrategyNumber; + default: + return InvalidStrategy; + } +} diff --git a/src/backend/access/spgist/spgutils.c b/src/backend/access/spgist/spgutils.c index 6e968048917..367c36ef9af 100644 --- a/src/backend/access/spgist/spgutils.c +++ b/src/backend/access/spgist/spgutils.c @@ -92,6 +92,8 @@ spghandler(PG_FUNCTION_ARGS) amroutine->amestimateparallelscan = NULL; amroutine->aminitparallelscan = NULL; amroutine->amparallelrescan = NULL; + amroutine->amtranslatestrategy = NULL; + amroutine->amtranslatecmptype = NULL; PG_RETURN_POINTER(amroutine); } |