diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2020-10-20 19:22:09 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2020-10-20 19:22:09 -0300 |
commit | 0e6b6f8c7192c82f62b4bbc0b40e9c6252a67bd1 (patch) | |
tree | 87fe186608ae0334530b0d34989f680659dfa2e7 /src/backend | |
parent | bd0677bb8a54683b05b75fc242bd5c757ce5edd8 (diff) | |
download | postgresql-0e6b6f8c7192c82f62b4bbc0b40e9c6252a67bd1.tar.gz postgresql-0e6b6f8c7192c82f62b4bbc0b40e9c6252a67bd1.zip |
Fix ALTER TABLE .. ENABLE/DISABLE TRIGGER recursion
More precisely, correctly handle the ONLY flag indicating not to
recurse. This was implemented in 86f575948c77 by recursing in
trigger.c, but that's the wrong place; use ATSimpleRecursion instead,
which behaves properly. However, because legacy inheritance has never
recursed in that situation, make sure to do that only for new-style
partitioning.
I noticed this problem while testing a fix for another bug in the
vicinity.
This has been wrong all along, so backpatch to 11.
Discussion: https://postgr.es/m/20201016235925.GA29829@alvherre.pgsql
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/commands/tablecmds.c | 2 | ||||
-rw-r--r-- | src/backend/commands/trigger.c | 21 |
2 files changed, 2 insertions, 21 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 1b53e0b03b1..933592b0fb3 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -4237,6 +4237,8 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd, case AT_DisableTrigAll: case AT_DisableTrigUser: ATSimplePermissions(rel, ATT_TABLE | ATT_FOREIGN_TABLE); + if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) + ATSimpleRecursion(wqueue, rel, cmd, recurse, lockmode); pass = AT_PASS_MISC; break; case AT_EnableRule: /* ENABLE/DISABLE RULE variants */ diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index e0dd1112f10..5d8eb29f247 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -1868,27 +1868,6 @@ EnableDisableTrigger(Relation rel, const char *tgname, heap_freetuple(newtup); - /* - * When altering FOR EACH ROW triggers on a partitioned table, do - * the same on the partitions as well. - */ - if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE && - (TRIGGER_FOR_ROW(oldtrig->tgtype))) - { - PartitionDesc partdesc = RelationGetPartitionDesc(rel); - int i; - - for (i = 0; i < partdesc->nparts; i++) - { - Relation part; - - part = relation_open(partdesc->oids[i], lockmode); - EnableDisableTrigger(part, NameStr(oldtrig->tgname), - fires_when, skip_system, lockmode); - table_close(part, NoLock); /* keep lock till commit */ - } - } - changed = true; } |