Re: enable/disable broken for statement triggers on partitioned tables
Dmitry Koval <d.koval@postgrespro.ru>
From: Dmitry Koval <d.koval@postgrespro.ru>
To: Amit Langote <amitlangote09@gmail.com>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>,
Simon Riggs <simon.riggs@enterprisedb.com>
Date: 2022-07-07T18:44:35Z
Lists: pgsql-hackers
Hi!
I've looked through the code and everything looks good.
But there is one thing I doubt.
Patch changes result of test:
----
create function trig_nothing() returns trigger language plpgsql
as $$ begin return null; end $$;
create table parent (a int) partition by list (a);
create table child1 partition of parent for values in (1);
create trigger tg after insert on parent
for each row execute procedure trig_nothing();
select tgrelid::regclass, tgname, tgenabled from pg_trigger
where tgrelid in ('parent'::regclass, 'child1'::regclass)
order by tgrelid::regclass::text;
alter table only parent enable always trigger tg; -- no recursion
select tgrelid::regclass, tgname, tgenabled from pg_trigger
where tgrelid in ('parent'::regclass, 'child1'::regclass)
order by tgrelid::regclass::text;
alter table parent enable always trigger tg; -- recursion
select tgrelid::regclass, tgname, tgenabled from pg_trigger
where tgrelid in ('parent'::regclass, 'child1'::regclass)
order by tgrelid::regclass::text;
drop table parent, child1;
drop function trig_nothing();
----
Results of vanilla + patch:
----
CREATE FUNCTION
CREATE TABLE
CREATE TABLE
CREATE TRIGGER
tgrelid | tgname | tgenabled
---------+--------+-----------
child1 | tg | O
parent | tg | O
(2 rows)
ALTER TABLE
tgrelid | tgname | tgenabled
---------+--------+-----------
child1 | tg | O
parent | tg | A
(2 rows)
ALTER TABLE
tgrelid | tgname | tgenabled
---------+--------+-----------
child1 | tg | O
parent | tg | A
(2 rows)
DROP TABLE
DROP FUNCTION
----
Results of vanilla:
----
CREATE FUNCTION
CREATE TABLE
CREATE TABLE
CREATE TRIGGER
tgrelid | tgname | tgenabled
---------+--------+-----------
child1 | tg | O
parent | tg | O
(2 rows)
ALTER TABLE
tgrelid | tgname | tgenabled
---------+--------+-----------
child1 | tg | O
parent | tg | A
(2 rows)
ALTER TABLE
tgrelid | tgname | tgenabled
---------+--------+-----------
child1 | tg | A
parent | tg | A
(2 rows)
DROP TABLE
DROP FUNCTION
----
The patch doesn't start recursion in case 'tgenabled' flag of parent
table is not changes.
Probably vanilla result is more correct.
--
With best regards,
Dmitry Koval
Postgres Professional: http://postgrespro.com
Commits
-
Fix ENABLE/DISABLE TRIGGER to handle recursion correctly
- ec0925c22a3d 16.0 landed
- e78fd9084587 15.0 landed
- 731d514ae58f 14.5 landed
- ab855663012c 13.8 landed
- 6e7b37264e96 12.12 landed
- ce8e066521d1 11.17 landed