1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-22 12:22:45 +03:00

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
This commit is contained in:
Peter Eisentraut
2025-02-02 10:26:04 +01:00
parent 119fc30dd5
commit c09e5a6a01
13 changed files with 169 additions and 0 deletions

View File

@@ -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;
}
}