diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2023-12-01 15:48:06 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2023-12-01 16:14:22 +0100 |
commit | 15d485921b1c2125d551e87a1f04be9d5c124b15 (patch) | |
tree | d50fc1db2e34002fdef07f2d201d972e744c9c51 /src/backend/commands | |
parent | 74a1bb168dd5fafe17e0f901543b286d9b15d3e4 (diff) | |
download | postgresql-15d485921b1c2125d551e87a1f04be9d5c124b15.tar.gz postgresql-15d485921b1c2125d551e87a1f04be9d5c124b15.zip |
Check collation when creating partitioned index
When creating a partitioned index, the partition key must be a subset
of the index's columns. But this currently doesn't check that the
collations between the partition key and the index definition match.
So you can construct a unique index that fails to enforce uniqueness.
(This would most likely involve a nondeterministic collation, so it
would have to be crafted explicitly and is not something that would
just happen by accident.)
This patch adds the required collation check. As a result, any
previously allowed unique index that has a collation mismatch would no
longer be allowed to be created.
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/3327cb54-f7f1-413b-8fdb-7a9dceebb938%40eisentraut.org
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/indexcmds.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index cf7b264cd11..c6234326206 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1003,10 +1003,13 @@ DefineIndex(Oid relationId, { if (key->partattrs[i] == indexInfo->ii_IndexAttrNumbers[j]) { - /* Matched the column, now what about the equality op? */ + /* Matched the column, now what about the collation and equality op? */ Oid idx_opfamily; Oid idx_opcintype; + if (key->partcollation[i] != collationObjectId[j]) + continue; + if (get_opclass_opfamily_and_input_type(classObjectId[j], &idx_opfamily, &idx_opcintype)) |