Re: BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT - Mailing list pgsql-bugs

From Alvaro Herrera
Subject Re: BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT
Date
Msg-id 201901101711.ngskkvwyqgr6@alvherre.pgsql
Whole thread Raw
In response to BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT  (Jesper Pedersen <jesper.pedersen@redhat.com>)
List pgsql-bugs
On 2019-Jan-10, PG Bug reporting form wrote:

> The following works
> 
> CREATE TABLE t1 (i1 INT NOT NULL, i2 INT NOT NULL) PARTITION BY HASH (i1);
> 
> \o /dev/null
> SELECT 'CREATE TABLE t1_p' || x::text || ' PARTITION OF t1
> FOR VALUES WITH (MODULUS 64, REMAINDER ' || x::text || ');'
> from generate_series(0,63) x;
> \gexec
> \o
> 
> ALTER TABLE ONLY t1 ADD CONSTRAINT uniq_t1_i1_i2 UNIQUE (i1, i2);
> 
> which gives
> 
> test=# \d+ t1
>                               Partitioned table "public.t1"
>  Column |  Type   | Collation | Nullable | Default | Storage | Stats target
> | Description 
> --------+---------+-----------+----------+---------+---------+--------------+-------------
>  i1     | integer |           | not null |         | plain   |             
> | 
>  i2     | integer |           | not null |         | plain   |             
> | 
> Partition key: HASH (i1)
> Indexes:
>     "uniq_t1_i1_i2" UNIQUE CONSTRAINT, btree (i1, i2) INVALID
> 
> 
> Removing ONLY from the ALTER command makes the index correct.

I'm not clear what problem you're reporting.  If you use ONLY, then the
command doesn't cascade to create the index on partitions, and the index
is marked invalid.  If you add the constraint to each partition and
ALTER INDEX ATTACH PARTITION, the index on t1 should become valid when
every partition of the table has its index.

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


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #15588: Garbled code when log in
Next
From: Tom Lane
Date:
Subject: Re: BUG #15577: Query returns different results when executed multiple times