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

Jehan-Guillaume de Rorthais <jgdr@dalibo.com>

From: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Tender Wang <tndrwang@gmail.com>, Junwang Zhao <zhjwpku@gmail.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>, Alexander Lakhin <exclusion@gmail.com>, Baehler Thomas SBB CFF FFS <thomas.baehler2@sbb.ch>, Guillaume Lelarge <guillaume@lelarge.info>, Michael Paquier <michael@paquier.xyz>
Date: 2024-09-04T22:57:28Z
Lists: pgsql-hackers

Attachments

On Mon, 2 Sep 2024 23:01:47 +0200
Jehan-Guillaume de Rorthais <jgdr@dalibo.com> wrote:

[…]

>   My proposal was to clean everything related to the old FK and use some
>   existing code path to create a fresh and cleaner one. This requires some
>   refactoring in existing code, but we would win a common path of code between
>   create/attach/detach, a cleaner catalog and easier code maintenance.
> 
>   I've finally been able to write a PoC that implement this by calling
>   addFkRecurseReferenced() from DetachPartitionFinalize(). I can't join
>   it here because it is currently an ugly draft and I still have some work
>   to do. But I would really like to have a little more time (one or two days)
>   to explore this avenue further before you commit yours, if you don't mind?
>   Or maybe you already have considered this avenue and rejected it?

Please, find in attachment a patch implementing this idea.

Regards,

Commits

  1. Fix some more bugs in foreign keys connecting partitioned tables

  2. Restructure foreign key handling code for ATTACH/DETACH

  3. Create foreign key triggers in partitioned tables too