Re: Bug in detaching a partition with a foreign key.
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Álvaro Herrera <alvherre@alvh.no-ip.org>
To: Sami Imseih <samimseih@gmail.com>
Cc: Amul Sul <sulamul@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-01-20T17:23:47Z
Lists: pgsql-hackers
Attachments
On 2025-Jan-20, Sami Imseih wrote: > The patch that Amul and I wrote both achieve the same result. > The approach that Amul took builds a list of constraint OIDs, > which could grow with the number of partitions and foreign keys > on those partitions. Maybe not a big deal? Nope, not a big deal. It would be a big deal if we were talking about 268 million partitions (>1GB palloc size), but that's impractical for other reasons. > In my suggestion [1], I just do one extra pg_constraint lookup > to determine If the relation on the parent and child constraint match, > and in that case we can skip the rest of the work to cut the > link as it's not needed. A pg_constraint lookup is going to be a lot slower. I attach Amul's patch again with the comments I added and your test case. Needs adaptation for backpatching to 16 and 15. Thanks! -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
Commits
-
Fix detach of a partition that has a toplevel FK to a partitioned table
- ddab512ebb97 16.7 landed
- 9b21f203dd87 18.0 landed
- 2f30847d1d04 17.3 landed
- 1bc092519b77 15.11 landed