Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails
Tender Wang <tndrwang@gmail.com>
From: Tender Wang <tndrwang@gmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Junwang Zhao <zhjwpku@gmail.com>,
Jehan-Guillaume de Rorthais <jgdr@dalibo.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>
Date: 2024-09-05T04:56:39Z
Lists: pgsql-hackers
Alvaro Herrera <alvherre@alvh.no-ip.org> 于2024年8月8日周四 06:50写道: > On 2024-Jul-26, Tender Wang wrote: > > > Junwang Zhao <zhjwpku@gmail.com> 于2024年7月26日周五 14:57写道: > > > > > There is a bug report[0] Tender comments might be the same issue as > > > this one, but I tried Alvaro's and mine patch, neither could solve > > > that problem, I did not tried Tender's earlier patch thought. I post > > > the test script below in case you are interested. > > > > My earlier patch should handle Alexander reported case. But I did not > > do more test. I'm not sure that wether or not has dismatching between > > pg_constraint and pg_trigger. > > > > I aggred with Alvaro said that "requires a much more invasive > > solution". > > Here's the patch which, as far as I can tell, fixes all the reported > problems (other than the one in bug 18541, for which I proposed an > unrelated fix in that thread[1]). If you can double-check, I would very > much appreciate that. Also, I think the test cases the patch adds > reflect the provided examples sufficiently, but if we're still failing > to cover some, please let me know. > When I review Jehan-Guillaume v2 patch, I found the below codes that need a little tweak. In DetachPartitionFinalize() /* * If the referenced side is partitioned (which we know because our * parent's constraint points to a different relation than ours) then * we must, in addition to the above, create pg_constraint rows that * point to each partition, each with its own action triggers. */ if (parentConForm->conrelid != conform->conrelid) I found that the above IF was always true, regardless of whether the referenced side is partitioned. Although find_all_inheritors() can return an empty children list when the referenced side is not partitioned, we can avoid much useless work. How about this way: if (get_rel_relkind(conform->confrelid) == RELKIND_PARTITIONED_TABLE) -- Thanks, Tender Wang
Commits
-
Fix some more bugs in foreign keys connecting partitioned tables
- f7d510a38245 16.5 landed
- 936ab6de9595 17.1 landed
- 2d5fe514052a 18.0 landed
- 1b216fceffe3 15.9 landed
-
Restructure foreign key handling code for ATTACH/DETACH
- d20194cead75 13.17 landed
- 5d83bad6b87d 15.9 landed
- 5914a22f6ea5 17.1 landed
- 53af9491a043 18.0 landed
- 46a8c27a7226 14.14 landed
- 2aaf2a28b87e 16.5 landed
-
Create foreign key triggers in partitioned tables too
- f4566345cf40 15.0 cited