mirror of
https://github.com/postgres/postgres.git
synced 2025-06-22 02:52:08 +03:00
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
This commit is contained in:
@ -1009,20 +1009,6 @@ DefineIndex(Oid tableId,
|
|||||||
eq_strategy, key->partopcintype[i], key->partopcintype[i],
|
eq_strategy, key->partopcintype[i], key->partopcintype[i],
|
||||||
key->partopfamily[i]);
|
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
|
* It may be possible to support UNIQUE constraints when partition
|
||||||
* keys are expressions, but is it worth it? Give up for now.
|
* keys are expressions, but is it worth it? Give up for now.
|
||||||
@ -1057,13 +1043,19 @@ DefineIndex(Oid tableId,
|
|||||||
Oid idx_eqop = InvalidOid;
|
Oid idx_eqop = InvalidOid;
|
||||||
|
|
||||||
if (stmt->unique && !stmt->iswithoutoverlaps)
|
if (stmt->unique && !stmt->iswithoutoverlaps)
|
||||||
idx_eqop = get_opfamily_member(idx_opfamily,
|
idx_eqop = get_opfamily_member_for_cmptype(idx_opfamily,
|
||||||
idx_opcintype,
|
idx_opcintype,
|
||||||
idx_opcintype,
|
idx_opcintype,
|
||||||
BTEqualStrategyNumber);
|
COMPARE_EQ);
|
||||||
else if (exclusion)
|
else if (exclusion)
|
||||||
idx_eqop = indexInfo->ii_ExclusionOps[j];
|
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)
|
if (ptkey_eqop == idx_eqop)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user