Re: A row-level trigger on a partitioned table is not created on a sub-partition created later
Alvaro Herrera <[email protected]> Fri, 27 Dec 2019 19:18:26 -0300
| Newsgroups | gmane.comp.db.postgresql.bugs |
|---|---|
| Message-ID | <[email protected]> |
On 2019-Dec-27, Alvaro Herrera wrote: > Working on getting your fix pushed now. Ran out of time for today, but I added this test that reproduces the issue -- fails without your patch, and works with it. One thing I just realized is that in next minors' release notes we should publish a recipe to fix catalogs for existing databases, unless we go for a fix that doesn't require changing the catalogs -- I don't know what that would be, though, but maybe it would not be totally insane to clone even internal triggers in the cases that matter. (I wonder if a better solution for the master branch would involve a new pg_trigger column that indicates the parent trigger for a cloned trigger. That would avoid pg_dump's new subquery. Also: would it be better to use pg_partition_ancestors instead of the sub-subquery? ... though that doesn't work in pg11 ...) -- Ãlvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
trigtest.patch
(text/x-diff, 3.9 KB)
commit 8a2318fcbdc501e6b230a22f6a6b1de57f871e74 Author: Alvaro Herrera <[email protected]> AuthorDate: Fri Dec 27 18:56:05 2019 -0300 CommitDate: Fri Dec 27 18:59:25 2019 -0300 Add failed test that shows the issue diff --git a/src/test/regress/expected/triggers.out b/src/test/regress/expected/triggers.out index 1e4053ceed..b91fbd0648 100644 --- a/src/test/regress/expected/triggers.out +++ b/src/test/regress/expected/triggers.out @@ -1981,15 +1981,22 @@ create trigger trg1 after insert on trigpart for each row execute procedure trig create table trigpart2 partition of trigpart for values from (1000) to (2000); create table trigpart3 (like trigpart); alter table trigpart attach partition trigpart3 for values from (2000) to (3000); +create table trigpart4 partition of trigpart for values from (3000) to (4000) partition by range (a); +create table trigpart41 partition of trigpart4 for values from (3000) to (3500); +create table trigpart42 (like trigpart); +alter table trigpart4 attach partition trigpart42 for values from (3500) to (4000); select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; - tgrelid | tgname | tgfoid ------------+--------+----------------- - trigpart | trg1 | trigger_nothing - trigpart1 | trg1 | trigger_nothing - trigpart2 | trg1 | trigger_nothing - trigpart3 | trg1 | trigger_nothing -(4 rows) + tgrelid | tgname | tgfoid +------------+--------+----------------- + trigpart | trg1 | trigger_nothing + trigpart1 | trg1 | trigger_nothing + trigpart2 | trg1 | trigger_nothing + trigpart3 | trg1 | trigger_nothing + trigpart4 | trg1 | trigger_nothing + trigpart41 | trg1 | trigger_nothing + trigpart42 | trg1 | trigger_nothing +(7 rows) drop trigger trg1 on trigpart1; -- fail ERROR: cannot drop trigger trg1 on table trigpart1 because trigger trg1 on table trigpart requires it @@ -2003,12 +2010,15 @@ HINT: You can drop trigger trg1 on table trigpart instead. drop table trigpart2; -- ok, trigger should be gone in that partition select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; - tgrelid | tgname | tgfoid ------------+--------+----------------- - trigpart | trg1 | trigger_nothing - trigpart1 | trg1 | trigger_nothing - trigpart3 | trg1 | trigger_nothing -(3 rows) + tgrelid | tgname | tgfoid +------------+--------+----------------- + trigpart | trg1 | trigger_nothing + trigpart1 | trg1 | trigger_nothing + trigpart3 | trg1 | trigger_nothing + trigpart4 | trg1 | trigger_nothing + trigpart41 | trg1 | trigger_nothing + trigpart42 | trg1 | trigger_nothing +(6 rows) drop trigger trg1 on trigpart; -- ok, all gone select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger diff --git a/src/test/regress/sql/triggers.sql b/src/test/regress/sql/triggers.sql index c21b6c124e..7cd835449c 100644 --- a/src/test/regress/sql/triggers.sql +++ b/src/test/regress/sql/triggers.sql @@ -1366,6 +1366,10 @@ create trigger trg1 after insert on trigpart for each row execute procedure trig create table trigpart2 partition of trigpart for values from (1000) to (2000); create table trigpart3 (like trigpart); alter table trigpart attach partition trigpart3 for values from (2000) to (3000); +create table trigpart4 partition of trigpart for values from (3000) to (4000) partition by range (a); +create table trigpart41 partition of trigpart4 for values from (3000) to (3500); +create table trigpart42 (like trigpart); +alter table trigpart4 attach partition trigpart42 for values from (3500) to (4000); select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; drop trigger trg1 on trigpart1; -- fail