Re: Cannot dump foreign key constraints on partitioned table - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Cannot dump foreign key constraints on partitioned table
Date
Msg-id 20180712034814.GB7352@paquier.xyz
Whole thread Raw
In response to Cannot dump foreign key constraints on partitioned table  (amul sul <sulamul@gmail.com>)
Responses Re: Cannot dump foreign key constraints on partitioned table  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Re: Cannot dump foreign key constraints on partitioned table  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-hackers
On Wed, Jul 11, 2018 at 03:49:59PM +0530, amul sul wrote:
> On the master head, getConstraints() function skips FK constraints for
> a partitioned table because of tbinfo->hastriggers is false.
>
> While creating FK constraints on the partitioned table, the FK triggers are only
> created on leaf partitions and skipped for the partitioned tables.

Oops.  Good catch.

> To fix this, either bypass the aforementioned condition of getConstraints() or
> set pg_class.relhastriggers to true for the partitioned table which doesn't seem
> to be the right solution, IMO.  Thoughts?

Changing pg_class.relhastriggers is out of scope because as far as I
know partitioned tables have no triggers, so the current value is
correct, and that would be a catalog change at this stage which would
cause any existing deployments of v11 to complain about the
inconsistency.  I think that this should be fixed client-side as the
attached does.

I have just stolen this SQL set from Alvaro to check the consistency of
the dumps created:
create table prim (a int primary key);
create table partfk (a int references prim) partition by range (a);
create table partfk1 partition of partfk for values from (0) to (100);
create table partfk2 partition of partfk for values from (100) to (200);

Thoughts?
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Etsuro Fujita
Date:
Subject: Re: Expression errors with "FOR UPDATE" and postgres_fdw with partitionwise join enabled.
Next
From: Nico Williams
Date:
Subject: Re: How can we submit code patches that implement our (pending)patents?