Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails

From: tender wang <tndrwang(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Jehan-Guillaume de Rorthais <jgdr(at)dalibo(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails
Date: 2023-08-03 09:34:40
Message-ID: CAHewXNmJT0JQXuYuJtm9CC6m+at8PS4X5ou1cezTNFhvD_ziHQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I think the code to determine that fk of a partition is inherited or not is
not enough.
For example, in this case, foreign key r_1_p_id_fkey1 is not inherited
from parent.

If conform->conparentid(in DetachPartitionFinalize func) is valid, we
should recheck confrelid(pg_constraint) field.

I try to fix this problem in the attached patch.
Any thoughts.

Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> 于2023年8月3日周四 17:02写道:

> On 2023-Aug-03, tender wang wrote:
>
> > I think old "sub-FK" should not be dropped, that will be violates
> foreign
> > key constraint.
>
> Yeah, I've been playing more with the patch and it is definitely not
> doing the right things. Just eyeballing the contents of pg_trigger and
> pg_constraint for partitions added by ALTER...ATTACH shows that the
> catalog contents are inconsistent with those added by CREATE TABLE
> PARTITION OF.
>
> --
> Álvaro Herrera PostgreSQL Developer —
> https://www.EnterpriseDB.com/
>

Attachment Content-Type Size
0001-Recheck-foreign-key-of-a-partition-is-inherited-from.patch text/plain 1.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2023-08-03 09:47:33 Re: Extract numeric filed in JSONB more effectively
Previous Message Matthias van de Meent 2023-08-03 09:31:01 Re: Adding a pg_servername() function