pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Jesper Pedersen <jesper.pedersen@redhat.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT
Date: Tue, 15 Jan 2019 16:35:32 -0300
Message-ID: <201901151935.zfadrzvyof4k@alvherre.pgsql> (raw)
In-Reply-To: <2815.1547577776@sss.pgh.pa.us>

On 2019-Jan-15, Tom Lane wrote:

> Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> > On 2019-Jan-10, Jesper Pedersen wrote:
> >> However, when you use ADD CONSTRAINT FOREIGN KEY you can't use ONLY, so
> >> would it be a good idea to make ADD CONSTRAINT UNIQUE behave the same way,
> >> i.e. error out ?
> 
> > I haven't investigated this angle.  It seems more complex than just a
> > simple bugfix, right?
> 
> Wouldn't that be throwing away the entire point of the ONLY behavior,
> ie to allow the component indexes to be built one at a time, without
> holding locks across the whole partition tree?

I now see that Jesper was talking about a completely different thing
than I was thinking.  I agree with you there -- it makes no sense to
reject that command ... particularly because pg_dump uses it.


What was on my head ("can we add ONLY to ADD FOREIGN KEY?") was the idea
that it'd be useful to construct the foreign keys in partitions, one by
one, and as a final step you construct a foreign key in the partitioned
table and then attach each FK in partition to the master one.  Right
now, adding the foreign key in the parent table just creates duplicates
in the partitions, which is silly.

create table foo (a int primary key);
create table barp (a int) partition by list (a);
create table barp1 partition of barp for values in (1);
create table barp2 partition of barp for values in (2);
alter table barp1 add foreign key (a) references foo;
alter table barp2 add foreign key (a) references foo;

At this point, the partitions have one FK each, and it would be neat to
merge them as a unit, creating a parent constraint.  But if you do:
  alter table barp add foreign key (a) references foo;
you end up with two FKs in each partition.

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




view thread (18+ messages)  latest in thread

Message-ID: <201901151935.zfadrzvyof4k@alvherre.pgsql>
Permalink:  ../201901151935.zfadrzvyof4k@alvherre.pgsql/
Also on:    postgresql.org/message-id/201901151935.zfadrzvyof4k@alvherre.pgsql

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: alvherre@2ndquadrant.com, tgl@sss.pgh.pa.us, jesper.pedersen@redhat.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT
  In-Reply-To: <201901151935.zfadrzvyof4k@alvherre.pgsql>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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