aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2019-01-14 19:25:19 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2019-01-14 19:28:10 -0300
commit0ad41cf537ea5f076273fcffa4c83a184bd9910f (patch)
tree820e791fcba3d1c42a65c9cbf4b2e9b4d35d17cc /src
parentbb24439cefead34f195c78f400982f3834593df6 (diff)
downloadpostgresql-0ad41cf537ea5f076273fcffa4c83a184bd9910f.tar.gz
postgresql-0ad41cf537ea5f076273fcffa4c83a184bd9910f.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/indexcmds.c2
-rw-r--r--src/test/regress/expected/indexing.out3
-rw-r--r--src/test/regress/sql/indexing.sql1
3 files changed, 5 insertions, 1 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index d2639036223..c8c64d9a425 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -721,7 +721,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 caacf3f7991..118f2c78df4 100644
--- a/src/test/regress/expected/indexing.out
+++ b/src/test/regress/expected/indexing.out
@@ -1411,3 +1411,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 6878cde5098..d4a64c18c7e 100644
--- a/src/test/regress/sql/indexing.sql
+++ b/src/test/regress/sql/indexing.sql
@@ -756,3 +756,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