pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
unique, partitioned index fails to distinguish index key from INCLUDEd columns
4+ messages / 2 participants
[nested] [flat]

* unique, partitioned index fails to distinguish index key from INCLUDEd columns
@ 2019-01-09 06:51 Justin Pryzby <pryzby@telsasoft.com>
  2019-01-14 22:31 ` Re: unique, partitioned index fails to distinguish index key from INCLUDEd columns Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Justin Pryzby @ 2019-01-09 06:51 UTC (permalink / raw)
  To: pgsql-hackers; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; Teodor Sigaev <teodor@sigaev.ru>

eb7ed3f3063401496e4aa4bd68fa33f0be31a72f Allow UNIQUE indexes on partitioned tables
8224de4f42ccf98e08db07b43d52fed72f962ebb Indexes with INCLUDE columns and their support in B-tree

postgres=# CREATE TABLE t(i int,j int) PARTITION BY LIST (i);
postgres=# CREATE TABLE t1 PARTITION OF t FOR VALUES IN (1);
postgres=# CREATE TABLE t2 PARTITION OF t FOR VALUES IN (2);

-- Correctly errors
postgres=# CREATE UNIQUE INDEX ON t(j);
ERROR:  insufficient columns in UNIQUE constraint definition
DETAIL:  UNIQUE constraint on table "t" lacks column "i" which is part of the partition key.

-- Fails to error
postgres=# CREATE UNIQUE INDEX ON t(j) INCLUDE(i);

-- Fail to enforce uniqueness across partitions due to failure to enforce inclusion of partition key in index KEY
postgres=# INSERT INTO t VALUES(1,1);
postgres=# INSERT INTO t VALUES(2,1); 

postgres=# SELECT * FROM t;
 i | j 
---+---
 1 | 1
 2 | 1
(2 rows)

I found this thread appears to have been close to discovering the issue ~9
months ago.
https://www.postgresql.org/message-id/flat/CAJGNTeO%3DBguEyG8wxMpU_Vgvg3nGGzy71zUQ0RpzEn_mb0bSWA%40m...

Justin




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: unique, partitioned index fails to distinguish index key from INCLUDEd columns
  2019-01-09 06:51 unique, partitioned index fails to distinguish index key from INCLUDEd columns Justin Pryzby <pryzby@telsasoft.com>
@ 2019-01-14 22:31 ` Alvaro Herrera <alvherre@2ndquadrant.com>
  2019-01-15 02:30   ` Re: unique, partitioned index fails to distinguish index key from INCLUDEd columns Justin Pryzby <pryzby@telsasoft.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Alvaro Herrera @ 2019-01-14 22:31 UTC (permalink / raw)
  To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: pgsql-hackers@postgresql.org, Teodor Sigaev <teodor@sigaev.ru>

On 2019-Jan-09, Justin Pryzby wrote:

> -- Fails to error
> postgres=# CREATE UNIQUE INDEX ON t(j) INCLUDE(i);
> 
> -- Fail to enforce uniqueness across partitions due to failure to enforce inclusion of partition key in index KEY
> postgres=# INSERT INTO t VALUES(1,1);
> postgres=# INSERT INTO t VALUES(2,1); 

Doh.  Fix pushed.  Commit 8224de4f42cc should have changed one
appearance of ii_NumIndexAttrs to ii_NumIndexKeyAttrs, but because of
the nature of concurrent development, nobody noticed.

Thanks for reporting.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: unique, partitioned index fails to distinguish index key from INCLUDEd columns
  2019-01-09 06:51 unique, partitioned index fails to distinguish index key from INCLUDEd columns Justin Pryzby <pryzby@telsasoft.com>
  2019-01-14 22:31 ` Re: unique, partitioned index fails to distinguish index key from INCLUDEd columns Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2019-01-15 02:30   ` Justin Pryzby <pryzby@telsasoft.com>
  2019-01-15 04:21     ` Re: unique, partitioned index fails to distinguish index key from INCLUDEd columns Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Justin Pryzby @ 2019-01-15 02:30 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-hackers@postgresql.org, Teodor Sigaev <teodor@sigaev.ru>

On Mon, Jan 14, 2019 at 07:31:07PM -0300, Alvaro Herrera wrote:
> On 2019-Jan-09, Justin Pryzby wrote:
> 
> > -- Fails to error
> > postgres=# CREATE UNIQUE INDEX ON t(j) INCLUDE(i);
> > 
> > -- Fail to enforce uniqueness across partitions due to failure to enforce inclusion of partition key in index KEY
> > postgres=# INSERT INTO t VALUES(1,1);
> > postgres=# INSERT INTO t VALUES(2,1); 
> 
> Doh.  Fix pushed.  Commit 8224de4f42cc should have changed one
> appearance of ii_NumIndexAttrs to ii_NumIndexKeyAttrs, but because of
> the nature of concurrent development, nobody noticed.

I figured as much - I thought to test this while trying to fall asleep,
without knowing they were developed in parallel.

Should backpatch to v11 ?
0ad41cf537ea5f076273fcffa4c83a184bd9910f

Thanks,
Justin




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: unique, partitioned index fails to distinguish index key from INCLUDEd columns
  2019-01-09 06:51 unique, partitioned index fails to distinguish index key from INCLUDEd columns Justin Pryzby <pryzby@telsasoft.com>
  2019-01-14 22:31 ` Re: unique, partitioned index fails to distinguish index key from INCLUDEd columns Alvaro Herrera <alvherre@2ndquadrant.com>
  2019-01-15 02:30   ` Re: unique, partitioned index fails to distinguish index key from INCLUDEd columns Justin Pryzby <pryzby@telsasoft.com>
@ 2019-01-15 04:21     ` Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Alvaro Herrera @ 2019-01-15 04:21 UTC (permalink / raw)
  To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: pgsql-hackers@postgresql.org, Teodor Sigaev <teodor@sigaev.ru>

On 2019-Jan-14, Justin Pryzby wrote:

> On Mon, Jan 14, 2019 at 07:31:07PM -0300, Alvaro Herrera wrote:

> > Doh.  Fix pushed.  Commit 8224de4f42cc should have changed one
> > appearance of ii_NumIndexAttrs to ii_NumIndexKeyAttrs, but because of
> > the nature of concurrent development, nobody noticed.
> 
> I figured as much - I thought to test this while trying to fall asleep,
> without knowing they were developed in parallel.

:-)

> Should backpatch to v11 ?
> 0ad41cf537ea5f076273fcffa4c83a184bd9910f

Yep, already done (src/tools/git_changelog in master):

Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
Branch: master [0ad41cf53] 2019-01-14 19:28:10 -0300
Branch: REL_11_STABLE [74aa7e046] 2019-01-14 19:25:19 -0300

    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


-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2019-01-15 04:21 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-01-09 06:51 unique, partitioned index fails to distinguish index key from INCLUDEd columns Justin Pryzby <pryzby@telsasoft.com>
2019-01-14 22:31 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-01-15 02:30   ` Justin Pryzby <pryzby@telsasoft.com>
2019-01-15 04:21     ` Alvaro Herrera <alvherre@2ndquadrant.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox