]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix oversight in FindTriggerIncompatibleWithInheritance.
authorEtsuro Fujita <efujita@postgresql.org>
Fri, 8 Aug 2025 08:35:00 +0000 (17:35 +0900)
committerEtsuro Fujita <efujita@postgresql.org>
Fri, 8 Aug 2025 08:35:00 +0000 (17:35 +0900)
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 501ed02cf.

Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Discussion: https://postgr.es/m/CAPmGK167mXzwzzmJ_0YZ3EZrbwiCxtM1vogH_8drqsE6PtxRYw%40mail.gmail.com
Backpatch-through: 13

src/backend/commands/trigger.c
src/test/regress/expected/triggers.out
src/test/regress/sql/triggers.sql

index 93b7ac1a442167fb33ded7a8cc8a55c48955e12c..71014c65b4950a12b3cda008040ffab0c7ed652a 100644 (file)
@@ -2285,6 +2285,8 @@ FindTriggerIncompatibleWithInheritance(TriggerDesc *trigdesc)
                {
                        Trigger    *trigger = &trigdesc->triggers[i];
 
+                       if (!TRIGGER_FOR_ROW(trigger->tgtype))
+                               continue;
                        if (trigger->tgoldtable != NULL || trigger->tgnewtable != NULL)
                                return trigger->tgname;
                }
index 872b9100e1a01b175767affac5a22a75b715eb79..1eb8fba0953706999187bc7fce7d5a36eb9d108b 100644 (file)
@@ -2769,6 +2769,10 @@ NOTICE:  trigger = child3_delete_trig, old table = (42,CCC)
 -- copy into parent sees parent-format tuples
 copy parent (a, b) from stdin;
 NOTICE:  trigger = parent_insert_trig, new table = (AAA,42), (BBB,42), (CCC,42)
+-- check detach/reattach behavior; statement triggers with transition tables
+-- should not prevent a table from becoming a partition again
+alter table parent detach partition child1;
+alter table parent attach partition child1 for values in ('AAA');
 -- DML affecting parent sees tuples collected from children even if
 -- there is no transition table trigger on the children
 drop trigger child1_insert_trig on child1;
@@ -2966,6 +2970,10 @@ NOTICE:  trigger = parent_insert_trig, new table = (AAA,42), (BBB,42), (CCC,42)
 create index on parent(b);
 copy parent (a, b) from stdin;
 NOTICE:  trigger = parent_insert_trig, new table = (DDD,42)
+-- check disinherit/reinherit behavior; statement triggers with transition
+-- tables should not prevent a table from becoming an inheritance child again
+alter table child1 no inherit parent;
+alter table child1 inherit parent;
 -- DML affecting parent sees tuples collected from children even if
 -- there is no transition table trigger on the children
 drop trigger child1_insert_trig on child1;
index d674b25c83be4a05d719754e6ce497afb9be97fb..5f7f75d7ba5d9169e15f118f3ac37948ac230177 100644 (file)
@@ -1935,6 +1935,11 @@ BBB      42
 CCC    42
 \.
 
+-- check detach/reattach behavior; statement triggers with transition tables
+-- should not prevent a table from becoming a partition again
+alter table parent detach partition child1;
+alter table parent attach partition child1 for values in ('AAA');
+
 -- DML affecting parent sees tuples collected from children even if
 -- there is no transition table trigger on the children
 drop trigger child1_insert_trig on child1;
@@ -2154,6 +2159,11 @@ copy parent (a, b) from stdin;
 DDD    42
 \.
 
+-- check disinherit/reinherit behavior; statement triggers with transition
+-- tables should not prevent a table from becoming an inheritance child again
+alter table child1 no inherit parent;
+alter table child1 inherit parent;
+
 -- DML affecting parent sees tuples collected from children even if
 -- there is no transition table trigger on the children
 drop trigger child1_insert_trig on child1;