diff options
author | Peter Eisentraut | 2025-02-21 07:34:35 +0000 |
---|---|---|
committer | Peter Eisentraut | 2025-02-21 08:07:16 +0000 |
commit | 7d6d2c4bbd730bd9af191d46d4fb01d5f5c30cf1 (patch) | |
tree | 211eef7a0cd3b72f6bd182a708ff5f8191918110 /src/backend | |
parent | 7202d72787d3b93b692feae62ee963238580c877 (diff) |
Drop opcintype from index AM strategy translation API
The type argument wasn't actually really necessary. It was a remnant
of converting the API of the gist strategy translation from using
opclass to using opfamily+opcintype (commits c09e5a6a016,
622f678c102). For looking up the gist translation function, we used
the convention "amproclefttype = amprocrighttype = opclass's
opcintype" (see pg_amproc.h). But each operator family should only
have one translation function, and getting the right type for the
lookup is sometimes cumbersome and fragile, so this is all
unnecessarily complicated.
To simplify this, change the gist stategy support procedure to take
"any", "any" as argument. (This is arbitrary but seems intuitive.
The alternative of using InvalidOid as argument(s) upsets various DDL
commands, so it's not practical.) Then we don't need opcintype for
the lookup, and we can remove it from all the API layers introduced by
commit c09e5a6a016.
This also adds some more documentation about the correct signature of
the gist support function and adds more checks in gistvalidate().
This was previously underspecified. (It relied implicitly on
convention mentioned above.)
Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/access/gist/gistutil.c | 4 | ||||
-rw-r--r-- | src/backend/access/gist/gistvalidate.c | 4 | ||||
-rw-r--r-- | src/backend/access/hash/hash.c | 4 | ||||
-rw-r--r-- | src/backend/access/index/amapi.c | 8 | ||||
-rw-r--r-- | src/backend/access/nbtree/nbtree.c | 4 | ||||
-rw-r--r-- | src/backend/catalog/index.c | 1 | ||||
-rw-r--r-- | src/backend/commands/indexcmds.c | 2 | ||||
-rw-r--r-- | src/backend/commands/tablecmds.c | 2 | ||||
-rw-r--r-- | src/backend/executor/execReplication.c | 2 | ||||
-rw-r--r-- | src/backend/replication/logical/relation.c | 6 |
10 files changed, 18 insertions, 19 deletions
diff --git a/src/backend/access/gist/gistutil.c b/src/backend/access/gist/gistutil.c index dbc4ac639a2..a6b701943d3 100644 --- a/src/backend/access/gist/gistutil.c +++ b/src/backend/access/gist/gistutil.c @@ -1095,13 +1095,13 @@ gist_stratnum_common(PG_FUNCTION_ARGS) * Returns InvalidStrategy if the function is not defined. */ StrategyNumber -gisttranslatecmptype(CompareType cmptype, Oid opfamily, Oid opcintype) +gisttranslatecmptype(CompareType cmptype, Oid opfamily) { Oid funcid; Datum result; /* Check whether the function is provided. */ - funcid = get_opfamily_proc(opfamily, opcintype, opcintype, GIST_STRATNUM_PROC); + funcid = get_opfamily_proc(opfamily, ANYOID, ANYOID, GIST_STRATNUM_PROC); if (!OidIsValid(funcid)) return InvalidStrategy; diff --git a/src/backend/access/gist/gistvalidate.c b/src/backend/access/gist/gistvalidate.c index ffefa12d97a..2a49e6d20f0 100644 --- a/src/backend/access/gist/gistvalidate.c +++ b/src/backend/access/gist/gistvalidate.c @@ -140,7 +140,9 @@ gistvalidate(Oid opclassoid) break; case GIST_STRATNUM_PROC: ok = check_amproc_signature(procform->amproc, INT2OID, true, - 1, 1, INT4OID); + 1, 1, INT4OID) && + procform->amproclefttype == ANYOID && + procform->amprocrighttype == ANYOID; break; default: ereport(INFO, diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c index 02ec1126a4c..b24aae415ea 100644 --- a/src/backend/access/hash/hash.c +++ b/src/backend/access/hash/hash.c @@ -927,7 +927,7 @@ hashbucketcleanup(Relation rel, Bucket cur_bucket, Buffer bucket_buf, } CompareType -hashtranslatestrategy(StrategyNumber strategy, Oid opfamily, Oid opcintype) +hashtranslatestrategy(StrategyNumber strategy, Oid opfamily) { if (strategy == HTEqualStrategyNumber) return COMPARE_EQ; @@ -935,7 +935,7 @@ hashtranslatestrategy(StrategyNumber strategy, Oid opfamily, Oid opcintype) } StrategyNumber -hashtranslatecmptype(CompareType cmptype, Oid opfamily, Oid opcintype) +hashtranslatecmptype(CompareType cmptype, Oid opfamily) { if (cmptype == COMPARE_EQ) return HTEqualStrategyNumber; diff --git a/src/backend/access/index/amapi.c b/src/backend/access/index/amapi.c index 5f53f49ec32..d6b8dad4d52 100644 --- a/src/backend/access/index/amapi.c +++ b/src/backend/access/index/amapi.c @@ -115,14 +115,14 @@ GetIndexAmRoutineByAmId(Oid amoid, bool noerror) * true, just return COMPARE_INVALID. */ CompareType -IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, Oid opcintype, bool missing_ok) +IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, bool missing_ok) { CompareType result; IndexAmRoutine *amroutine; amroutine = GetIndexAmRoutineByAmId(amoid, false); if (amroutine->amtranslatestrategy) - result = amroutine->amtranslatestrategy(strategy, opfamily, opcintype); + result = amroutine->amtranslatestrategy(strategy, opfamily); else result = COMPARE_INVALID; @@ -140,14 +140,14 @@ IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, Oid o * to the given cmptype. If true, just return InvalidStrategy. */ StrategyNumber -IndexAmTranslateCompareType(CompareType cmptype, Oid amoid, Oid opfamily, Oid opcintype, bool missing_ok) +IndexAmTranslateCompareType(CompareType cmptype, Oid amoid, Oid opfamily, bool missing_ok) { StrategyNumber result; IndexAmRoutine *amroutine; amroutine = GetIndexAmRoutineByAmId(amoid, false); if (amroutine->amtranslatecmptype) - result = amroutine->amtranslatecmptype(cmptype, opfamily, opcintype); + result = amroutine->amtranslatecmptype(cmptype, opfamily); else result = InvalidStrategy; diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c index dc244ae24c7..411d5ac0b5f 100644 --- a/src/backend/access/nbtree/nbtree.c +++ b/src/backend/access/nbtree/nbtree.c @@ -1513,7 +1513,7 @@ btgettreeheight(Relation rel) } CompareType -bttranslatestrategy(StrategyNumber strategy, Oid opfamily, Oid opcintype) +bttranslatestrategy(StrategyNumber strategy, Oid opfamily) { switch (strategy) { @@ -1533,7 +1533,7 @@ bttranslatestrategy(StrategyNumber strategy, Oid opfamily, Oid opcintype) } StrategyNumber -bttranslatecmptype(CompareType cmptype, Oid opfamily, Oid opcintype) +bttranslatecmptype(CompareType cmptype, Oid opfamily) { switch (cmptype) { diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index cdabf780244..f37b990c81d 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -2692,7 +2692,6 @@ BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii) IndexAmTranslateCompareType(COMPARE_EQ, index->rd_rel->relam, index->rd_opfamily[i], - index->rd_opcintype[i], false); ii->ii_UniqueOps[i] = get_opfamily_member(index->rd_opfamily[i], diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index f8d3ea820e1..c92f5620ec1 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -2468,7 +2468,7 @@ GetOperatorFromCompareType(Oid opclass, Oid rhstype, CompareType cmptype, /* * Ask the index AM to translate to its internal stratnum */ - *strat = IndexAmTranslateCompareType(cmptype, amid, opfamily, opcintype, true); + *strat = IndexAmTranslateCompareType(cmptype, amid, opfamily, true); if (*strat == InvalidStrategy) ereport(ERROR, errcode(ERRCODE_UNDEFINED_OBJECT), diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 9d8754be7e5..ce7d115667e 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -10113,7 +10113,7 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, */ for_overlaps = with_period && i == numpks - 1; cmptype = for_overlaps ? COMPARE_OVERLAP : COMPARE_EQ; - eqstrategy = IndexAmTranslateCompareType(cmptype, amid, opfamily, opcintype, true); + eqstrategy = IndexAmTranslateCompareType(cmptype, amid, opfamily, true); if (eqstrategy == InvalidStrategy) ereport(ERROR, errcode(ERRCODE_UNDEFINED_OBJECT), diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c index 5f7613cc831..5cef54f00ed 100644 --- a/src/backend/executor/execReplication.c +++ b/src/backend/executor/execReplication.c @@ -91,7 +91,7 @@ build_replindex_scan_key(ScanKey skey, Relation rel, Relation idxrel, */ optype = get_opclass_input_type(opclass->values[index_attoff]); opfamily = get_opclass_family(opclass->values[index_attoff]); - eq_strategy = IndexAmTranslateCompareType(COMPARE_EQ, idxrel->rd_rel->relam, opfamily, optype, false); + eq_strategy = IndexAmTranslateCompareType(COMPARE_EQ, idxrel->rd_rel->relam, opfamily, false); operator = get_opfamily_member(opfamily, optype, optype, eq_strategy); diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c index e9ad90d64a5..46d15b824e3 100644 --- a/src/backend/replication/logical/relation.c +++ b/src/backend/replication/logical/relation.c @@ -837,11 +837,9 @@ IsIndexUsableForReplicaIdentityFull(Relation idxrel, AttrMap *attrmap) for (int i = 0; i < idxrel->rd_index->indnkeyatts; i++) { Oid opfamily; - Oid opcintype; - if (!get_opclass_opfamily_and_input_type(indclass->values[i], &opfamily, &opcintype)) - return false; - if (IndexAmTranslateCompareType(COMPARE_EQ, idxrel->rd_rel->relam, opfamily, opcintype, true) == InvalidStrategy) + opfamily = get_opclass_family(indclass->values[i]); + if (IndexAmTranslateCompareType(COMPARE_EQ, idxrel->rd_rel->relam, opfamily, true) == InvalidStrategy) return false; } |