From: Alvaro Herrera Date: Mon, 14 Jan 2019 22:25:19 +0000 (-0300) Subject: Fix unique INCLUDE indexes on partitioned tables X-Git-Tag: REL_11_2~75 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=74aa7e046e4a3927d506bc651261724539f67139;p=thirdparty%2Fpostgresql.git 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 eb7ed3f30634 and 8224de4f42cc. Reported-by: Justin Pryzby Discussion: https://postgr.es/m/20190109065109.GA4285@telsasoft.com --- diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 965b9f0d232..fec5bc5dd64 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -722,7 +722,7 @@ DefineIndex(Oid relationId, errdetail("%s constraints cannot be used when partition keys include expressions.", constraint_type))); - for (j = 0; j < indexInfo->ii_NumIndexAttrs; j++) + for (j = 0; j < indexInfo->ii_NumIndexKeyAttrs; j++) { if (key->partattrs[i] == indexInfo->ii_IndexAttrNumbers[j]) { diff --git a/src/test/regress/expected/indexing.out b/src/test/regress/expected/indexing.out index 225f4e95274..11fdcdc3b21 100644 --- a/src/test/regress/expected/indexing.out +++ b/src/test/regress/expected/indexing.out @@ -1384,3 +1384,6 @@ insert into covidxpart values (4, 1); insert into covidxpart values (4, 1); ERROR: duplicate key value violates unique constraint "covidxpart4_a_b_idx" DETAIL: Key (a)=(4) already exists. +create unique index on covidxpart (b) include (a); -- should fail +ERROR: insufficient columns in UNIQUE constraint definition +DETAIL: UNIQUE constraint on table "covidxpart" lacks column "a" which is part of the partition key. diff --git a/src/test/regress/sql/indexing.sql b/src/test/regress/sql/indexing.sql index f145384fbc9..8c5a0024eef 100644 --- a/src/test/regress/sql/indexing.sql +++ b/src/test/regress/sql/indexing.sql @@ -739,3 +739,4 @@ create unique index on covidxpart4 (a); alter table covidxpart attach partition covidxpart4 for values in (4); insert into covidxpart values (4, 1); insert into covidxpart values (4, 1); +create unique index on covidxpart (b) include (a); -- should fail