Skip to content

Commit afdb4cd

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 095e83d commit afdb4cd

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
@@ -2045,6 +2045,8 @@ FindTriggerIncompatibleWithInheritance(TriggerDesc *trigdesc)
20452045
{
20462046
Trigger *trigger = &trigdesc->triggers[i];
20472047

2048+
if (!TRIGGER_FOR_ROW(trigger->tgtype))
2049+
continue;
20482050
if (trigger->tgoldtable != NULL || trigger->tgnewtable != NULL)
20492051
return trigger->tgname;
20502052
}

src/test/regress/expected/triggers.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,10 @@ NOTICE: trigger = child3_delete_trig, old table = (42,CCC)
29302930
-- copy into parent sees parent-format tuples
29312931
copy parent (a, b) from stdin;
29322932
NOTICE: trigger = parent_insert_trig, new table = (AAA,42), (BBB,42), (CCC,42)
2933+
-- check detach/reattach behavior; statement triggers with transition tables
2934+
-- should not prevent a table from becoming a partition again
2935+
alter table parent detach partition child1;
2936+
alter table parent attach partition child1 for values in ('AAA');
29332937
-- DML affecting parent sees tuples collected from children even if
29342938
-- there is no transition table trigger on the children
29352939
drop trigger child1_insert_trig on child1;
@@ -3127,6 +3131,10 @@ NOTICE: trigger = parent_insert_trig, new table = (AAA,42), (BBB,42), (CCC,42)
31273131
create index on parent(b);
31283132
copy parent (a, b) from stdin;
31293133
NOTICE: trigger = parent_insert_trig, new table = (DDD,42)
3134+
-- check disinherit/reinherit behavior; statement triggers with transition
3135+
-- tables should not prevent a table from becoming an inheritance child again
3136+
alter table child1 no inherit parent;
3137+
alter table child1 inherit parent;
31303138
-- DML affecting parent sees tuples collected from children even if
31313139
-- there is no transition table trigger on the children
31323140
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
@@ -2038,6 +2038,11 @@ BBB 42
20382038
CCC 42
20392039
\.
20402040

2041+
-- check detach/reattach behavior; statement triggers with transition tables
2042+
-- should not prevent a table from becoming a partition again
2043+
alter table parent detach partition child1;
2044+
alter table parent attach partition child1 for values in ('AAA');
2045+
20412046
-- DML affecting parent sees tuples collected from children even if
20422047
-- there is no transition table trigger on the children
20432048
drop trigger child1_insert_trig on child1;
@@ -2257,6 +2262,11 @@ copy parent (a, b) from stdin;
22572262
DDD 42
22582263
\.
22592264

2265+
-- check disinherit/reinherit behavior; statement triggers with transition
2266+
-- tables should not prevent a table from becoming an inheritance child again
2267+
alter table child1 no inherit parent;
2268+
alter table child1 inherit parent;
2269+
22602270
-- DML affecting parent sees tuples collected from children even if
22612271
-- there is no transition table trigger on the children
22622272
drop trigger child1_insert_trig on child1;

0 commit comments

Comments
 (0)