Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ad41cf

Browse files
committed
Fix unique INCLUDE indexes on partitioned tables
We were considering the INCLUDE columns as part of the key, allowing unicity-violating rows to be inserted in different partitions. Concurrent development conflict in eb7ed3f and 8224de4. Reported-by: Justin Pryzby Discussion: https://postgr.es/m/[email protected]
1 parent bb24439 commit 0ad41cf

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

src/backend/commands/indexcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ DefineIndex(Oid relationId,
721721
errdetail("%s constraints cannot be used when partition keys include expressions.",
722722
constraint_type)));
723723

724-
for (j = 0; j < indexInfo->ii_NumIndexAttrs; j++)
724+
for (j = 0; j < indexInfo->ii_NumIndexKeyAttrs; j++)
725725
{
726726
if (key->partattrs[i] == indexInfo->ii_IndexAttrNumbers[j])
727727
{

src/test/regress/expected/indexing.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,3 +1411,6 @@ insert into covidxpart values (4, 1);
14111411
insert into covidxpart values (4, 1);
14121412
ERROR: duplicate key value violates unique constraint "covidxpart4_a_b_idx"
14131413
DETAIL: Key (a)=(4) already exists.
1414+
create unique index on covidxpart (b) include (a); -- should fail
1415+
ERROR: insufficient columns in UNIQUE constraint definition
1416+
DETAIL: UNIQUE constraint on table "covidxpart" lacks column "a" which is part of the partition key.

src/test/regress/sql/indexing.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,3 +756,4 @@ create unique index on covidxpart4 (a);
756756
alter table covidxpart attach partition covidxpart4 for values in (4);
757757
insert into covidxpart values (4, 1);
758758
insert into covidxpart values (4, 1);
759+
create unique index on covidxpart (b) include (a); -- should fail

0 commit comments

Comments
 (0)