Re: enable/disable broken for statement triggers on partitioned tables

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Simon Riggs <simon(dot)riggs(at)enterprisedb(dot)com>
Subject: Re: enable/disable broken for statement triggers on partitioned tables
Date: 2022-07-13 03:08:33
Message-ID: CA+HiwqFUmjnNAwn9SOeeRpcEWXwkjx5hbZZ8CHxGBUCD8a0ssA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Fri, Jul 8, 2022 at 3:44 AM Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru> wrote:
> 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.

Thanks for the review and this test case.

I agree that the patch shouldn't have changed that behavior, so I've
fixed the patch so that EnableDisableTrigger() recurses even if the
parent trigger is unchanged.

--
Thanks, Amit Langote
EDB: http://www.enterprisedb.com

Attachment Content-Type Size
v2-0001-Fix-ENABLE-DISABLE-TRIGGER-to-handle-recursion-co.patch application/octet-stream 17.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2022-07-13 03:25:18 Re: Add --{no-,}bypassrls flags to createuser
Previous Message David Rowley 2022-07-13 03:06:10 Re: Some clean-up work in get_cheapest_group_keys_order()