Skip to content

Commit 5d40b3c

Browse files
committed
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
1 parent 0bd6822 commit 5d40b3c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/backend/commands/indexcmds.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,10 +935,13 @@ DefineIndex(Oid relationId,
935935
{
936936
if (key->partattrs[i] == indexInfo->ii_IndexAttrNumbers[j])
937937
{
938-
/* Matched the column, now what about the equality op? */
938+
/* Matched the column, now what about the collation and equality op? */
939939
Oid idx_opfamily;
940940
Oid idx_opcintype;
941941

942+
if (key->partcollation[i] != collationObjectId[j])
943+
continue;
944+
942945
if (get_opclass_opfamily_and_input_type(classObjectId[j],
943946
&idx_opfamily,
944947
&idx_opcintype))

0 commit comments

Comments
 (0)