Re: Rename of triggers for partitioned tables
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Arne Roland <A.Roland@index.de>
Cc: David Steele <david@pgmasters.net>, Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2021-03-29T13:25:36Z
Lists: pgsql-hackers
On 2021-Mar-29, Arne Roland wrote:
> @@ -1475,7 +1467,12 @@ renametrig(RenameStmt *stmt)
> tuple = heap_copytuple(tuple); /* need a modifiable copy */
> trigform = (Form_pg_trigger) GETSTRUCT(tuple);
> tgoid = trigform->oid;
> -
> + if (tgparent != 0 && tgparent != trigform->tgparentid) {
> + ereport(ERROR,
> + (errcode(ERRCODE_UNDEFINED_OBJECT),
> + errmsg("trigger \"%s\" for table \"%s\" is not dependent on the trigger on \"%s\"",
> + stmt->subname, RelationGetRelationName(targetrel), stmt->relation->relname)));
> + }
I think this is not what we want to do. What you're doing here as I
understand is traversing the inheritance hierarchy down using the
trigger name, and then fail if the trigger with that name has a
different parent or if no trigger with that name exists in the child.
What we really want to have happen, is to search the list of triggers in
the child, see which one has tgparentid=<the one we're renaming>, and
rename that one -- regardless of what name it had originally.
Also, you added grammar support for the ONLY keyword in the command, but
it doesn't do anything different when given that flag, does it? At
least, I see no change or addition to recursion behavior in ATExecCmd.
I would expect that if I say "ALTER TRIGGER .. ON ONLY tab" then it
renames the trigger on table "tab" but not on its child tables; only if
I remove the ONLY from the command it recurses.
I think it would be good to have a new test for pg_dump that verifies
that this stuff is doing the right thing.
--
Álvaro Herrera 39°49'30"S 73°17'W
"Siempre hay que alimentar a los dioses, aunque la tierra esté seca" (Orual)
Commits
-
Remove newly added useless assertion check
- 21b3aa9c8faf 15.0 landed
-
Make ALTER TRIGGER RENAME consistent for partitioned tables
- 80ba4bb38353 15.0 landed
-
Fix pg_dump for disabled triggers on partitioned tables
- ccfc3cbb341a 11.13 cited
-
Preserve firing-on state when cloning row triggers to partitions
- fed35bd4a650 11.13 cited
-
Fix ALTER TABLE .. ENABLE/DISABLE TRIGGER recursion
- bbb927b4db9b 14.0 cited
-
Record parents of triggers
- b9b408c48724 13.0 cited
-
Allow FOR EACH ROW triggers on partitioned tables
- 86f575948c77 11.0 cited