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

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Tender Wang <tndrwang(at)gmail(dot)com>
Cc: Junwang Zhao <zhjwpku(at)gmail(dot)com>, Jehan-Guillaume de Rorthais <jgdr(at)dalibo(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Alexander Lakhin <exclusion(at)gmail(dot)com>, Baehler Thomas SBB CFF FFS <thomas(dot)baehler2(at)sbb(dot)ch>, Guillaume Lelarge <guillaume(at)lelarge(dot)info>
Subject: Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails
Date: 2024-08-21 22:00:46
Message-ID: 202408212200.xm4zwv6sxifd@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2024-Aug-19, Alvaro Herrera wrote:

> I haven't pushed it yet, mostly because of being unsure about not doing
> anything for the oldest branches (14 and back).

Last night, after much mulling on this, it occurred to me that one easy
way out of this problem for the old branches, without having to write
more code, is to simply remove the constraint from the partition when
it's detached (but only if they reference a partitioned relation). It's
not a great solution, but at least we're no longer leaving bogus catalog
entries around. That would be like the attached patch, which was cut
from 14 and applies cleanly to 12 and 13. I'd throw in a couple of
tests and call it a day.

(TBH the idea of leaving the partition without a foreign key feels to me
like travelling in a car without a seat belt -- it feels instinctively
dangerous. This is why I went such lengths to keep FKs on detach
initially. But I'm not inclined to spend more time on this issue.
However ... what about fixing catalog content that's already broken
after past detach ops?)

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/

Attachment Content-Type Size
v14-0001-drop-constraint-when-detaching.patch text/x-diff 4.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2024-08-21 22:54:40 Re: CREATE SUBSCRIPTION - add missing test case
Previous Message Tom Lane 2024-08-21 21:25:42 Re: Index AM API cleanup