Skip to content

Commit 3863c6f

Browse files
author
Etsuro Fujita
committed
Fix oversight in FindTriggerIncompatibleWithInheritance.
This function is called from ATExecAttachPartition/ATExecAddInherit, which prevent tables with row-level triggers with transition tables from becoming partitions or inheritance children, to check if there is such a trigger on the given table, but failed to check if a found trigger is row-level, causing the caller functions to needlessly prevent a table with only a statement-level trigger with transition tables from becoming a partition or inheritance child. Repair. Oversight in commit 501ed02. Author: Etsuro Fujita <etsuro.fujita@gmail.com> Discussion: https://postgr.es/m/CAPmGK167mXzwzzmJ_0YZ3EZrbwiCxtM1vogH_8drqsE6PtxRYw%40mail.gmail.com Backpatch-through: 13
1 parent 9cca445 commit 3863c6f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/backend/commands/trigger.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,8 @@ FindTriggerIncompatibleWithInheritance(TriggerDesc *trigdesc)
22852285
{
22862286
Trigger *trigger = &trigdesc->triggers[i];
22872287

2288+
if (!TRIGGER_FOR_ROW(trigger->tgtype))
2289+
continue;
22882290
if (trigger->tgoldtable != NULL || trigger->tgnewtable != NULL)
22892291
return trigger->tgname;
22902292
}

src/test/regress/expected/triggers.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,6 +3016,10 @@ NOTICE: trigger = child3_delete_trig, old table = (42,CCC)
30163016
-- copy into parent sees parent-format tuples
30173017
copy parent (a, b) from stdin;
30183018
NOTICE: trigger = parent_insert_trig, new table = (AAA,42), (BBB,42), (CCC,42)
3019+
-- check detach/reattach behavior; statement triggers with transition tables
3020+
-- should not prevent a table from becoming a partition again
3021+
alter table parent detach partition child1;
3022+
alter table parent attach partition child1 for values in ('AAA');
30193023
-- DML affecting parent sees tuples collected from children even if
30203024
-- there is no transition table trigger on the children
30213025
drop trigger child1_insert_trig on child1;
@@ -3213,6 +3217,10 @@ NOTICE: trigger = parent_insert_trig, new table = (AAA,42), (BBB,42), (CCC,42)
32133217
create index on parent(b);
32143218
copy parent (a, b) from stdin;
32153219
NOTICE: trigger = parent_insert_trig, new table = (DDD,42)
3220+
-- check disinherit/reinherit behavior; statement triggers with transition
3221+
-- tables should not prevent a table from becoming an inheritance child again
3222+
alter table child1 no inherit parent;
3223+
alter table child1 inherit parent;
32163224
-- DML affecting parent sees tuples collected from children even if
32173225
-- there is no transition table trigger on the children
32183226
drop trigger child1_insert_trig on child1;

src/test/regress/sql/triggers.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,11 @@ BBB 42
21102110
CCC 42
21112111
\.
21122112

2113+
-- check detach/reattach behavior; statement triggers with transition tables
2114+
-- should not prevent a table from becoming a partition again
2115+
alter table parent detach partition child1;
2116+
alter table parent attach partition child1 for values in ('AAA');
2117+
21132118
-- DML affecting parent sees tuples collected from children even if
21142119
-- there is no transition table trigger on the children
21152120
drop trigger child1_insert_trig on child1;
@@ -2329,6 +2334,11 @@ copy parent (a, b) from stdin;
23292334
DDD 42
23302335
\.
23312336

2337+
-- check disinherit/reinherit behavior; statement triggers with transition
2338+
-- tables should not prevent a table from becoming an inheritance child again
2339+
alter table child1 no inherit parent;
2340+
alter table child1 inherit parent;
2341+
23322342
-- DML affecting parent sees tuples collected from children even if
23332343
-- there is no transition table trigger on the children
23342344
drop trigger child1_insert_trig on child1;

0 commit comments

Comments
 (0)