Skip to content

Commit f278e1f

Browse files
committed
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 <mark.dilger@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
1 parent 7317e64 commit f278e1f

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/backend/commands/indexcmds.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,20 +1009,6 @@ DefineIndex(Oid tableId,
10091009
eq_strategy, key->partopcintype[i], key->partopcintype[i],
10101010
key->partopfamily[i]);
10111011

1012-
/*
1013-
* We'll need to be able to identify the equality operators
1014-
* associated with index columns, too. We know what to do with
1015-
* btree opclasses; if there are ever any other index types that
1016-
* support unique indexes, this logic will need extension. But if
1017-
* we have an exclusion constraint (or a temporal PK), it already
1018-
* knows the operators, so we don't have to infer them.
1019-
*/
1020-
if (stmt->unique && !stmt->iswithoutoverlaps && accessMethodId != BTREE_AM_OID)
1021-
ereport(ERROR,
1022-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1023-
errmsg("cannot match partition key to an index using access method \"%s\"",
1024-
accessMethodName)));
1025-
10261012
/*
10271013
* It may be possible to support UNIQUE constraints when partition
10281014
* keys are expressions, but is it worth it? Give up for now.
@@ -1057,13 +1043,19 @@ DefineIndex(Oid tableId,
10571043
Oid idx_eqop = InvalidOid;
10581044

10591045
if (stmt->unique && !stmt->iswithoutoverlaps)
1060-
idx_eqop = get_opfamily_member(idx_opfamily,
1061-
idx_opcintype,
1062-
idx_opcintype,
1063-
BTEqualStrategyNumber);
1046+
idx_eqop = get_opfamily_member_for_cmptype(idx_opfamily,
1047+
idx_opcintype,
1048+
idx_opcintype,
1049+
COMPARE_EQ);
10641050
else if (exclusion)
10651051
idx_eqop = indexInfo->ii_ExclusionOps[j];
1066-
Assert(idx_eqop);
1052+
1053+
if (!idx_eqop)
1054+
ereport(ERROR,
1055+
errcode(ERRCODE_UNDEFINED_OBJECT),
1056+
errmsg("could not identify an equality operator for type %s", format_type_be(idx_opcintype)),
1057+
errdetail("There is no suitable operator in operator family \"%s\" for access method \"%s\".",
1058+
get_opfamily_name(idx_opfamily, false), get_am_name(get_opfamily_method(idx_opfamily))));
10671059

10681060
if (ptkey_eqop == idx_eqop)
10691061
{

0 commit comments

Comments
 (0)