Re: BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jesper Pedersen <jesper(dot)pedersen(at)redhat(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT
Date: 2019-01-17 22:23:06
Message-ID: 201901172223.lm3iihkw7hn4@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2019-Jan-16, Amit Langote wrote:

> Why not just move the code in clone_fk_constraints() that checks if the
> constraint equivalent of the parent's constraint is present in the
> partition and simply attach the two without creating a new copy for the
> partition to a new function in tablecmds.c and call the function from both
> clone_fk_constraints() and ATAddForeignKeyConstraint()? Attached is what
> I'm thinking.

Well, the whole point of my proposal is that the FK-creating code
recurses to partitions by calling ATAddForeignKeyConstraint, and IMO
that's the wrong level to recurse at; we should instead recurse by
calling clone_fk_constraints() as a whole. That's not readibly possible
with the current code arrangement because of layering, but after
backpatching (as attached) the two patches I mentioned, I end up with
the following, which I think is much cleaner. (Also, this code layout
plays much better with my project to continue to extend FKs so that they
are allowed to point to partitioned tables; see the other thread).

The attached patches are for pg11; they don't apply to master. The
changes are uninteresting.

The tests added by the final commit clearly show dupe FKs being created
in some of the cases, if you run them without applying the code fixes,
and none afterwards.

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

Attachment Content-Type Size
0001-Refactor-duplicate-code-into-DeconstructFkConstraint.patch text/x-diff 16.3 KB
0002-Move-CloneForeignKeyConstraints-to-tablecmds.c.patch text/x-diff 21.9 KB
0003-fix-dupe-FK-constraints.patch text/x-diff 9.1 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2019-01-18 00:28:32 Re: Is temporary functions feature official/supported? Found some issues with it.
Previous Message Alexander Lakhin 2019-01-17 19:27:21 Re: BUG #15594: Unstable tests in contrib/test_decoding/output_iso/