Skip to content

Commit 4766eef

Browse files
committed
Fix another issue with ENABLE/DISABLE TRIGGER on partitioned tables.
In v13 and v14, the ENABLE/DISABLE TRIGGER USER variant malfunctioned on cloned triggers, failing to find the clones because it thought they were system triggers. Other variants of ENABLE/DISABLE TRIGGER would improperly apply a superuserness check. Fix by adjusting the is-it- a-system-trigger check to match reality in those branches. (As far as I can find, this is the only place that got it wrong.) There's no such bug in v15/HEAD, because we revised the catalog representation of system triggers to be what this code was expecting. However, add the test case to these branches anyway, because this area is visibly pretty fragile. Also remove an obsoleted comment. The recent v15/HEAD commit 6949b92 fixed a nearby bug. I now see that my commit message for that was inaccurate: the behavior of recursing to clone triggers is older than v15, but it didn't apply to the case in v13/v14 because in those branches parent partitioned tables have no pg_trigger entries for foreign-key triggers. But add the test case from that commit to v13/v14, just to show what is happening there. Per bug #17886 from DzmitryH. Discussion: https://postgr.es/m/17886-5406d5d828aa4aa3@postgresql.org
1 parent 3d6a984 commit 4766eef

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/backend/commands/trigger.c

-5
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,6 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString,
863863

864864
/*
865865
* Build the new pg_trigger tuple.
866-
*
867-
* When we're creating a trigger in a partition, we mark it as internal,
868-
* even though we don't do the isInternal magic in this function. This
869-
* makes the triggers in partitions identical to the ones in the
870-
* partitioned tables, except that they are marked internal.
871866
*/
872867
memset(nulls, false, sizeof(nulls));
873868

src/test/regress/expected/triggers.out

+12
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,18 @@ select tgrelid::regclass, tgname, tgenabled from pg_trigger
27182718
parent | tg_stmt | A
27192719
(3 rows)
27202720

2721+
-- This variant malfunctioned in some releases.
2722+
alter table parent disable trigger user;
2723+
select tgrelid::regclass, tgname, tgenabled from pg_trigger
2724+
where tgrelid in ('parent'::regclass, 'child1'::regclass)
2725+
order by tgrelid::regclass::text, tgname;
2726+
tgrelid | tgname | tgenabled
2727+
---------+---------+-----------
2728+
child1 | tg | D
2729+
parent | tg | D
2730+
parent | tg_stmt | D
2731+
(3 rows)
2732+
27212733
drop table parent, child1;
27222734
-- Check processing of foreign key triggers
27232735
create table parent (a int primary key, f int references parent)

src/test/regress/sql/triggers.sql

+5
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,11 @@ select tgrelid::regclass, tgname, tgenabled from pg_trigger
18781878
-- The following is a no-op for the parent trigger but not so
18791879
-- for the child trigger, so recursion should be applied.
18801880
alter table parent enable always trigger tg;
1881+
select tgrelid::regclass, tgname, tgenabled from pg_trigger
1882+
where tgrelid in ('parent'::regclass, 'child1'::regclass)
1883+
order by tgrelid::regclass::text, tgname;
1884+
-- This variant malfunctioned in some releases.
1885+
alter table parent disable trigger user;
18811886
select tgrelid::regclass, tgname, tgenabled from pg_trigger
18821887
where tgrelid in ('parent'::regclass, 'child1'::regclass)
18831888
order by tgrelid::regclass::text, tgname;

0 commit comments

Comments
 (0)