[PATCH] Fix trigger argument propagation to child partitions - Mailing list pgsql-hackers

From Patrick McHardy
Subject [PATCH] Fix trigger argument propagation to child partitions
Date
Msg-id 20190709130027.amr2cavjvo7rdvac@access1.trash.net
Whole thread Raw
Responses Re: [PATCH] Fix trigger argument propagation to child partitions  (Tomas Vondra <tomas.vondra@2ndquadrant.com>)
List pgsql-hackers
The following patch fixes propagation of arguments to the trigger
function to child partitions both when initially creating the trigger
and when adding new partitions to a partitioned table.

The included regression test should demonstrate the problem, for clarity
repeated in slightly more readable form here:

bb=> create table parted_trig (a int) partition by list (a);
CREATE TABLE
bb=> create table parted_trig1 partition of parted_trig for values in (1);
CREATE TABLE
bb=> create or replace function trigger_notice() returns trigger as $$
bb$>   declare
bb$>     arg1 text = TG_ARGV[0];
bb$>     arg2 integer = TG_ARGV[1];
bb$>   begin
bb$>     raise notice 'trigger % on % % % for % args % %', TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL, arg1,
arg2;
bb$>     return null;
bb$>   end;
bb$>   $$ language plpgsql;
CREATE FUNCTION
bb=> create trigger aaa after insert on parted_trig for each row execute procedure trigger_notice('text', 1);
CREATE TRIGGER
bb=> \d parted_trig
                 Tabelle »public.parted_trig«
 Spalte |   Typ   | Sortierfolge | NULL erlaubt? | Vorgabewert 
--------+---------+--------------+---------------+-------------
 a      | integer |              |               | 
Partitionsschlüssel: LIST (a)
Trigger:
    aaa AFTER INSERT ON parted_trig FOR EACH ROW EXECUTE PROCEDURE trigger_notice('text', '1')
Anzahl Partitionen: 1 (Mit \d+ alle anzeigen.)

bb=> \d parted_trig1
                 Tabelle »public.parted_trig1«
 Spalte |   Typ   | Sortierfolge | NULL erlaubt? | Vorgabewert 
--------+---------+--------------+---------------+-------------
 a      | integer |              |               | 
Partition von: parted_trig FOR VALUES IN (1)
Trigger:
    aaa AFTER INSERT ON parted_trig1 FOR EACH ROW EXECUTE PROCEDURE trigger_notice()

Fixed:

bb=> \d parted_trig1
                 Tabelle »public.parted_trig1«
 Spalte |   Typ   | Sortierfolge | NULL erlaubt? | Vorgabewert 
--------+---------+--------------+---------------+-------------
 a      | integer |              |               | 
Partition von: parted_trig FOR VALUES IN (1)
Trigger:
    aaa AFTER INSERT ON parted_trig1 FOR EACH ROW EXECUTE PROCEDURE trigger_notice('text', '1')

Patch is against 11.4, but applies to master with minor offset.

All regression test pass.

Attachment

pgsql-hackers by date:

Previous
From: Julien Rouhaud
Date:
Subject: Re: Add parallelism and glibc dependent only options to reindexdb
Next
From: Ryan Lambert
Date:
Subject: Re: FETCH FIRST clause PERCENT option