]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix oversight in FindTriggerIncompatibleWithInheritance.
authorEtsuro Fujita <efujita@postgresql.org>
Fri, 8 Aug 2025 08:35:03 +0000 (17:35 +0900)
committerEtsuro Fujita <efujita@postgresql.org>
Fri, 8 Aug 2025 08:35:03 +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 1f0a8046dfc93f48fa60b7f2c06ad7e339ef64ee..d3ba0a3440e23790b3fa6cea3908c4fc70ece588 100644 (file)
@@ -2120,6 +2120,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 3660802b94a21a773f4c00d5d5d56b0c18a59a7b..768f2e607000bbcdf63bcfd769a26bd7cced40b2 100644 (file)
@@ -2930,6 +2930,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;
@@ -3127,6 +3131,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 42cf0f3f741755889f0407c3679eb3f70870ff44..71f3b6d4656672b6f8a090dc6416687a89b97a60 100644 (file)
@@ -2038,6 +2038,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;
@@ -2257,6 +2262,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;