diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2025-02-03 08:14:27 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2025-02-03 10:53:18 +0100 |
commit | 622f678c10202c8a0b350794d504eeef7b773e90 (patch) | |
tree | 7ff9730b065921fa91afe7f3c79243ccf5d478bc /src/backend/commands/tablecmds.c | |
parent | 43a15eb9400dba2b0b97be72d1a3745a6a6f7136 (diff) |
Integrate GistTranslateCompareType() into IndexAmTranslateCompareType()
This turns GistTranslateCompareType() into a callback function of the
gist index AM instead of a standalone function. The existing callers
are changed to use IndexAmTranslateCompareType(). This then makes
that code not hardcoded toward gist.
This means in particular that the temporal keys code is now
independent of gist. Also, this generalizes commit 74edabce7a3, so
other index access methods other than the previously hardcoded ones
could now work as REPLICA IDENTITY in a logical replication
subscriber.
Author: Mark Dilger <mark.dilger@enterprisedb.com>
Co-authored-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/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 9827b27af8a..18f64db6e39 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -10002,37 +10002,21 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, CompareType cmptype; bool for_overlaps = with_period && i == numpks - 1; - /* - * GiST indexes are required to support temporal foreign keys - * because they combine equals and overlaps. - */ - if (amid != GIST_AM_OID) - elog(ERROR, "only GiST indexes are supported for temporal foreign keys"); - cmptype = for_overlaps ? COMPARE_OVERLAP : COMPARE_EQ; /* - * An opclass can use whatever strategy numbers it wants, so we - * ask the opclass what number it actually uses instead of our RT* - * constants. + * An index AM can use whatever strategy numbers it wants, so we + * ask it what number it actually uses. */ - eqstrategy = GistTranslateCompareType(opclasses[i], cmptype); + eqstrategy = IndexAmTranslateCompareType(cmptype, amid, opfamily, opcintype, true); if (eqstrategy == InvalidStrategy) - { - HeapTuple tuple; - - tuple = SearchSysCache1(CLAOID, ObjectIdGetDatum(opclasses[i])); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "cache lookup failed for operator class %u", opclasses[i]); - ereport(ERROR, errcode(ERRCODE_UNDEFINED_OBJECT), for_overlaps ? errmsg("could not identify an overlaps operator for foreign key") : errmsg("could not identify an equality operator for foreign key"), - errdetail("Could not translate compare type %d for operator class \"%s\" for access method \"%s\".", - cmptype, NameStr(((Form_pg_opclass) GETSTRUCT(tuple))->opcname), "gist")); - } + errdetail("Could not translate compare type %d for operator family \"%s\", input type %s, access method \"%s\".", + cmptype, get_opfamily_name(opfamily, false), format_type_be(opcintype), get_am_name(amid))); } else { @@ -10041,7 +10025,7 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, * other index AMs support unique indexes. If we ever did have * other types of unique indexes, we'd need a way to determine * which operator strategy number is equality. (We could use - * something like GistTranslateCompareType.) + * IndexAmTranslateCompareType.) */ if (amid != BTREE_AM_OID) elog(ERROR, "only b-tree indexes are supported for foreign keys"); |