Re: DETACH PARTITION and FOR EACH ROW triggers on partitioned tables
Justin Pryzby <pryzby@telsasoft.com>
From: Justin Pryzby <pryzby@telsasoft.com>
To: Amit Langote <amitlangote09@gmail.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>, Tom Lane <tgl@sss.pgh.pa.us>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-04-20T19:57:40Z
Lists: pgsql-hackers
Attachments
On Mon, Apr 20, 2020 at 06:35:44PM +0900, Amit Langote wrote: > On Mon, Apr 20, 2020 at 5:49 AM Justin Pryzby <pryzby@telsasoft.com> wrote: > > On Sun, Apr 19, 2020 at 03:13:29PM -0400, Alvaro Herrera wrote: > > > What happens if you detach the parent? I mean, should the trigger > > > removal recurse to children? > > > > It think it should probably exactly undo what CloneRowTriggersToPartition does. > > ..and I guess you're trying to politely say that it didn't. I tried to fix in > > v4 - please check if that's right. > > Looks correct to me. Maybe have a test cover that? I included such a test with the v4 patch. > > > > But if we remove trigger during DETACH, then it's *not* the same as a trigger > > > > that was defined on the child, and I suggest that in v13 we should make that > > > > visible. > > > > > > Hmm, interesting point -- whether the trigger is partition or not is > > > important because it affects what happens on detach. I agree that we > > > should make it visible. Is the proposed single bit "PARTITION" good > > > enough, or should we indicate what's the ancestor table that defines the > > > partition? > > > > Yea, it's an obvious thing to do. > > This: > > + "false AS tgisinternal"), > + (pset.sversion >= 13000 ? > + "pg_partition_root(t.tgrelid) AS parent" : > + "'' AS parent"), > + oid); > > > looks wrong, because the actual partition root may not also be the > trigger parent root, for example: Sigh, right. > The following gets the correct parent for me: > > - (pset.sversion >= 13000 ? > - "pg_partition_root(t.tgrelid) AS parent" : > - "'' AS parent"), > + (pset.sversion >= 130000 ? > + "(SELECT relid" > + " FROM pg_trigger, pg_partition_ancestors(t.tgrelid)" > + " WHERE tgname = t.tgname AND tgrelid = relid" > + " AND tgparentid = 0) AS parent" : > + " null AS parent"), I'm happy to see that this doesn't require a recursive cte, at least. I was trying to think how to break it by returning multiple results or results out of order, but I think that can't happen. > Also, how about, for consistency, making the parent table labeling of > the trigger look similar to that for the foreign constraint, so > Triggers: > TABLE "f1" TRIGGER "trig" BEFORE INSERT ON f11 FOR EACH ROW EXECUTE FUNCTION trigfunc() I'll leave that for committer to decide. I split into separate patches since only 0001 should be backpatched (with s/OidIsValid(tgparentid)/isPartitionTrigger/). -- Justin
Commits
-
psql \d: Display table where trigger is defined, if inherited
- c33869cc3bfc 13.0 landed
-
Document partitiong tables ancillary object handling some more
- cda02408f20d 12.3 landed
- 97dcd5cd1500 11.8 landed
- 8803506c411e 13.0 landed
-
Fix detaching partitions with cloned row triggers
- e26c8a6b31e9 12.3 landed
- afccd76f1cce 13.0 landed
- 0b83c47216b0 11.8 landed