]> granicus.if.org Git - postgresql/commitdiff
Fix unique INCLUDE indexes on partitioned tables
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 14 Jan 2019 22:25:19 +0000 (19:25 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 14 Jan 2019 22:25:19 +0000 (19:25 -0300)
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

src/backend/commands/indexcmds.c
src/test/regress/expected/indexing.out
src/test/regress/sql/indexing.sql

index 965b9f0d23268abe9f646bb1c58180ec8bb12ede..fec5bc5dd64d3e2febd3b2478d9401fe54d06235 100644 (file)
@@ -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])
                                {
index 225f4e9527401ac486ffd400cdc81cd0112c66ac..11fdcdc3b21d975fbf199e60b1693e7f7c355410 100644 (file)
@@ -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.
index f145384fbc9c04c69fcba57cb90396b597a0b998..8c5a0024eef47e63058dbcffc600d9f0bd052ec4 100644 (file)
@@ -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