pgsql: Fix detaching partitions with cloned row triggers - Mailing list pgsql-committers

From Alvaro Herrera
Subject pgsql: Fix detaching partitions with cloned row triggers
Date
Msg-id E1jQxA6-0001nm-6B@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix detaching partitions with cloned row triggers

When a partition is detached, any triggers that had been cloned from its
parent were not properly disentangled from its parent triggers.
This resulted in triggers that could not be dropped because they
depended on the trigger in the trigger in the no-longer-parent table:
  ALTER TABLE t DETACH PARTITION t1;
  DROP TRIGGER trig ON t1;
    ERROR:  cannot drop trigger trig on table t1 because trigger trig on table t requires it
    HINT:  You can drop trigger trig on table t instead.

Moreover the table can no longer be re-attached to its parent, because
the trigger name is already taken:
  ALTER TABLE t ATTACH PARTITION t1 FOR VALUES FROM (1)TO(2);
    ERROR:  trigger "trig" for relation "t1" already exists

The former is a bug introduced in commit 86f575948c77.  (The latter is
not necessarily a bug, but it makes the bug more uncomfortable.)

To avoid the complexity that would be needed to tell whether the trigger
has a local definition that has to be merged with the one coming from
the parent table, establish the behavior that the trigger is removed
when the table is detached.

Backpatch to pg11.

Author: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/20200408152412.GZ2228@telsasoft.com

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e26c8a6b31e9ce657b0185812a8eecb0c1811321

Modified Files
--------------
doc/src/sgml/ref/create_trigger.sgml   |  1 +
src/backend/commands/tablecmds.c       | 64 ++++++++++++++++++++++++++++++++++
src/test/regress/expected/triggers.out | 45 ++++++++++++++++++++++++
src/test/regress/sql/triggers.sql      | 21 +++++++++++
4 files changed, 131 insertions(+)


pgsql-committers by date:

Previous
From: Peter Geoghegan
Date:
Subject: pgsql: Consider outliers in split interval calculation.
Next
From: Tom Lane
Date:
Subject: pgsql: Fix minor violations of FunctionCallInvoke usage protocol.