Skip to content

Commit 0a6aaf0

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 72e7872 commit 0a6aaf0

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/backend/commands/trigger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ EnableDisableTriggerNew(Relation rel, const char *tgname,
15891589
{
15901590
Form_pg_trigger oldtrig = (Form_pg_trigger) GETSTRUCT(tuple);
15911591

1592-
if (oldtrig->tgisinternal)
1592+
if (oldtrig->tgisinternal && !OidIsValid(oldtrig->tgparentid))
15931593
{
15941594
/* system trigger ... ok to process? */
15951595
if (skip_system)

src/test/regress/expected/triggers.out

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,6 +2692,45 @@ select tgrelid::regclass, tgname, tgenabled from pg_trigger
26922692
parent | tg_stmt | A
26932693
(3 rows)
26942694

2695+
-- This variant malfunctioned in some releases.
2696+
alter table parent disable trigger user;
2697+
select tgrelid::regclass, tgname, tgenabled from pg_trigger
2698+
where tgrelid in ('parent'::regclass, 'child1'::regclass)
2699+
order by tgrelid::regclass::text, tgname;
2700+
tgrelid | tgname | tgenabled
2701+
---------+---------+-----------
2702+
child1 | tg | D
2703+
parent | tg | D
2704+
parent | tg_stmt | D
2705+
(3 rows)
2706+
2707+
drop table parent, child1;
2708+
-- Check processing of foreign key triggers
2709+
create table parent (a int primary key, f int references parent)
2710+
partition by list (a);
2711+
create table child1 partition of parent for values in (1);
2712+
select tgrelid::regclass, rtrim(tgname, '0123456789') as tgname,
2713+
tgfoid::regproc, tgenabled
2714+
from pg_trigger where tgrelid in ('parent'::regclass, 'child1'::regclass)
2715+
order by tgrelid::regclass::text, tgfoid;
2716+
tgrelid | tgname | tgfoid | tgenabled
2717+
---------+-------------------------+---------------------+-----------
2718+
child1 | RI_ConstraintTrigger_c_ | "RI_FKey_check_ins" | O
2719+
child1 | RI_ConstraintTrigger_c_ | "RI_FKey_check_upd" | O
2720+
(2 rows)
2721+
2722+
-- Before v15, this has no effect because parent has no triggers:
2723+
alter table parent disable trigger all;
2724+
select tgrelid::regclass, rtrim(tgname, '0123456789') as tgname,
2725+
tgfoid::regproc, tgenabled
2726+
from pg_trigger where tgrelid in ('parent'::regclass, 'child1'::regclass)
2727+
order by tgrelid::regclass::text, tgfoid;
2728+
tgrelid | tgname | tgfoid | tgenabled
2729+
---------+-------------------------+---------------------+-----------
2730+
child1 | RI_ConstraintTrigger_c_ | "RI_FKey_check_ins" | O
2731+
child1 | RI_ConstraintTrigger_c_ | "RI_FKey_check_upd" | O
2732+
(2 rows)
2733+
26952734
drop table parent, child1;
26962735
-- Verify that firing state propagates correctly on creation, too
26972736
CREATE TABLE trgfire (i int) PARTITION BY RANGE (i);

src/test/regress/sql/triggers.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,27 @@ alter table parent enable always trigger tg;
18481848
select tgrelid::regclass, tgname, tgenabled from pg_trigger
18491849
where tgrelid in ('parent'::regclass, 'child1'::regclass)
18501850
order by tgrelid::regclass::text, tgname;
1851+
-- This variant malfunctioned in some releases.
1852+
alter table parent disable trigger user;
1853+
select tgrelid::regclass, tgname, tgenabled from pg_trigger
1854+
where tgrelid in ('parent'::regclass, 'child1'::regclass)
1855+
order by tgrelid::regclass::text, tgname;
1856+
drop table parent, child1;
1857+
1858+
-- Check processing of foreign key triggers
1859+
create table parent (a int primary key, f int references parent)
1860+
partition by list (a);
1861+
create table child1 partition of parent for values in (1);
1862+
select tgrelid::regclass, rtrim(tgname, '0123456789') as tgname,
1863+
tgfoid::regproc, tgenabled
1864+
from pg_trigger where tgrelid in ('parent'::regclass, 'child1'::regclass)
1865+
order by tgrelid::regclass::text, tgfoid;
1866+
-- Before v15, this has no effect because parent has no triggers:
1867+
alter table parent disable trigger all;
1868+
select tgrelid::regclass, rtrim(tgname, '0123456789') as tgname,
1869+
tgfoid::regproc, tgenabled
1870+
from pg_trigger where tgrelid in ('parent'::regclass, 'child1'::regclass)
1871+
order by tgrelid::regclass::text, tgfoid;
18511872
drop table parent, child1;
18521873

18531874
-- Verify that firing state propagates correctly on creation, too

0 commit comments

Comments
 (0)