mirror of
https://github.com/postgres/postgres.git
synced 2025-06-19 04:21:08 +03:00
Don't clone internal triggers to partitions
Trigger cloning to partitions was supposed to occur for user-visible
triggers only, but during development the protection that prevented it
from occurring to internal triggers was lost. Reinstate it, as well as
add a test case to ensure internal triggers (in the tested case,
triggers implementing a deferred unique constraint) are not cloned.
Without the code fix, the partitions in the test end up with different
numbers of triggers, which is clearly wrong ...
Bug in 86f575948c
.
Discussion: https://postgr.es/m/20180403214903.ozfagwjcpk337uw7@alvherre.pgsql
This commit is contained in:
@ -14336,6 +14336,10 @@ CloneRowTriggersToPartition(Relation parent, Relation partition)
|
|||||||
if (!TRIGGER_FOR_ROW(trigForm->tgtype))
|
if (!TRIGGER_FOR_ROW(trigForm->tgtype))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* We don't clone internal triggers, either */
|
||||||
|
if (trigForm->tgisinternal)
|
||||||
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Complain if we find an unexpected trigger type.
|
* Complain if we find an unexpected trigger type.
|
||||||
*/
|
*/
|
||||||
|
@ -2234,6 +2234,29 @@ NOTICE: trigger parted_trigger on parted_trigger_3_1 AFTER UPDATE for ROW: (a,b
|
|||||||
NOTICE: trigger parted_trigger on parted_trigger_3_2 AFTER UPDATE for ROW: (a,b)=(2003,eeeeb)
|
NOTICE: trigger parted_trigger on parted_trigger_3_2 AFTER UPDATE for ROW: (a,b)=(2003,eeeeb)
|
||||||
drop table parted_trigger;
|
drop table parted_trigger;
|
||||||
drop function trigger_notice_ab();
|
drop function trigger_notice_ab();
|
||||||
|
-- Make sure we don't end up with unnecessary copies of triggers, when
|
||||||
|
-- cloning them.
|
||||||
|
create table trg_clone (a int) partition by range (a);
|
||||||
|
create table trg_clone1 partition of trg_clone for values from (0) to (1000);
|
||||||
|
alter table trg_clone add constraint uniq unique (a) deferrable;
|
||||||
|
create table trg_clone2 partition of trg_clone for values from (1000) to (2000);
|
||||||
|
create table trg_clone3 partition of trg_clone for values from (2000) to (3000)
|
||||||
|
partition by range (a);
|
||||||
|
create table trg_clone_3_3 partition of trg_clone3 for values from (2000) to (2100);
|
||||||
|
select tgrelid::regclass, count(*) from pg_trigger
|
||||||
|
where tgrelid::regclass in ('trg_clone', 'trg_clone1', 'trg_clone2',
|
||||||
|
'trg_clone3', 'trg_clone_3_3')
|
||||||
|
group by tgrelid::regclass order by tgrelid::regclass;
|
||||||
|
tgrelid | count
|
||||||
|
---------------+-------
|
||||||
|
trg_clone | 1
|
||||||
|
trg_clone1 | 1
|
||||||
|
trg_clone2 | 1
|
||||||
|
trg_clone3 | 1
|
||||||
|
trg_clone_3_3 | 1
|
||||||
|
(5 rows)
|
||||||
|
|
||||||
|
drop table trg_clone;
|
||||||
--
|
--
|
||||||
-- Test the interaction between transition tables and both kinds of
|
-- Test the interaction between transition tables and both kinds of
|
||||||
-- inheritance. We'll dump the contents of the transition tables in a
|
-- inheritance. We'll dump the contents of the transition tables in a
|
||||||
|
@ -1578,6 +1578,21 @@ drop table parted_trigger;
|
|||||||
|
|
||||||
drop function trigger_notice_ab();
|
drop function trigger_notice_ab();
|
||||||
|
|
||||||
|
-- Make sure we don't end up with unnecessary copies of triggers, when
|
||||||
|
-- cloning them.
|
||||||
|
create table trg_clone (a int) partition by range (a);
|
||||||
|
create table trg_clone1 partition of trg_clone for values from (0) to (1000);
|
||||||
|
alter table trg_clone add constraint uniq unique (a) deferrable;
|
||||||
|
create table trg_clone2 partition of trg_clone for values from (1000) to (2000);
|
||||||
|
create table trg_clone3 partition of trg_clone for values from (2000) to (3000)
|
||||||
|
partition by range (a);
|
||||||
|
create table trg_clone_3_3 partition of trg_clone3 for values from (2000) to (2100);
|
||||||
|
select tgrelid::regclass, count(*) from pg_trigger
|
||||||
|
where tgrelid::regclass in ('trg_clone', 'trg_clone1', 'trg_clone2',
|
||||||
|
'trg_clone3', 'trg_clone_3_3')
|
||||||
|
group by tgrelid::regclass order by tgrelid::regclass;
|
||||||
|
drop table trg_clone;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Test the interaction between transition tables and both kinds of
|
-- Test the interaction between transition tables and both kinds of
|
||||||
-- inheritance. We'll dump the contents of the transition tables in a
|
-- inheritance. We'll dump the contents of the transition tables in a
|
||||||
|
Reference in New Issue
Block a user