Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 74aa7e0

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/20190109065109.GA4285@telsasoft.com
1 parent 20b4ed8 commit 74aa7e0

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
@@ -722,7 +722,7 @@ DefineIndex(Oid relationId,
722722
errdetail("%s constraints cannot be used when partition keys include expressions.",
723723
constraint_type)));
724724

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

src/test/regress/expected/indexing.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,3 +1384,6 @@ insert into covidxpart values (4, 1);
13841384
insert into covidxpart values (4, 1);
13851385
ERROR: duplicate key value violates unique constraint "covidxpart4_a_b_idx"
13861386
DETAIL: Key (a)=(4) already exists.
1387+
create unique index on covidxpart (b) include (a); -- should fail
1388+
ERROR: insufficient columns in UNIQUE constraint definition
1389+
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
@@ -739,3 +739,4 @@ create unique index on covidxpart4 (a);
739739
alter table covidxpart attach partition covidxpart4 for values in (4);
740740
insert into covidxpart values (4, 1);
741741
insert into covidxpart values (4, 1);
742+
create unique index on covidxpart (b) include (a); -- should fail

0 commit comments

Comments
 (0)