summaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorPeter Eisentraut2025-03-18 10:25:36 +0000
committerPeter Eisentraut2025-03-18 10:25:36 +0000
commitf278e1fe300ab1b7d43c3efb55a29aa17e5f5dda (patch)
treeb51f02d63bd72e47b884f2e74babb7a60b2a0283 /src/backend/commands
parent7317e641268fb9b08d32519920adf1f16c8591ea (diff)
Allow non-btree unique indexes for partition keys
We were rejecting non-btree indexes in some cases owing to the inability to determine the equality operators for other index AMs; that problem no longer exists, because we can look up the equality operator using COMPARE_EQ. The problem of not knowing the strategy number for equality in other index AMs is already resolved. Stop rejecting the indexes upfront, and instead reject any for which the equality operator lookup fails. Author: Mark Dilger <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/[email protected]
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/indexcmds.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 32ff3ca9a28..89cc83e8843 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -1010,20 +1010,6 @@ DefineIndex(Oid tableId,
key->partopfamily[i]);
/*
- * We'll need to be able to identify the equality operators
- * associated with index columns, too. We know what to do with
- * btree opclasses; if there are ever any other index types that
- * support unique indexes, this logic will need extension. But if
- * we have an exclusion constraint (or a temporal PK), it already
- * knows the operators, so we don't have to infer them.
- */
- if (stmt->unique && !stmt->iswithoutoverlaps && accessMethodId != BTREE_AM_OID)
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("cannot match partition key to an index using access method \"%s\"",
- accessMethodName)));
-
- /*
* It may be possible to support UNIQUE constraints when partition
* keys are expressions, but is it worth it? Give up for now.
*/
@@ -1057,13 +1043,19 @@ DefineIndex(Oid tableId,
Oid idx_eqop = InvalidOid;
if (stmt->unique && !stmt->iswithoutoverlaps)
- idx_eqop = get_opfamily_member(idx_opfamily,
- idx_opcintype,
- idx_opcintype,
- BTEqualStrategyNumber);
+ idx_eqop = get_opfamily_member_for_cmptype(idx_opfamily,
+ idx_opcintype,
+ idx_opcintype,
+ COMPARE_EQ);
else if (exclusion)
idx_eqop = indexInfo->ii_ExclusionOps[j];
- Assert(idx_eqop);
+
+ if (!idx_eqop)
+ ereport(ERROR,
+ errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("could not identify an equality operator for type %s", format_type_be(idx_opcintype)),
+ errdetail("There is no suitable operator in operator family \"%s\" for access method \"%s\".",
+ get_opfamily_name(idx_opfamily, false), get_am_name(get_opfamily_method(idx_opfamily))));
if (ptkey_eqop == idx_eqop)
{