Re: Multi-insert into a partitioned table with before insert rowtrigger causes server crash on latest HEAD - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Multi-insert into a partitioned table with before insert rowtrigger causes server crash on latest HEAD
Date
Msg-id 20181012180007.zn2u6hkac5blwrzs@alap3.anarazel.de
Whole thread Raw
In response to Multi-insert into a partitioned table with before insert row triggercauses server crash on latest HEAD  (Ashutosh Sharma <ashu.coek88@gmail.com>)
Responses Re: Multi-insert into a partitioned table with before insert rowtrigger causes server crash on latest HEAD  (Ashutosh Sharma <ashu.coek88@gmail.com>)
List pgsql-hackers
Hi,

On 2018-10-12 21:16:25 +0530, Ashutosh Sharma wrote:
> The copy command on partitioned table causes server crash when before
> insert row trigger is created on one of its partition. Please find the
> following test-case  to reproduce the crash.
> 
> -- create a partitioned table
> create table part_copy_test  (a int, b int, c text) partition by list (b);
> create table part_copy_test_a1 partition of part_copy_test for values in(1);
> create table part_copy_test_a2 partition of part_copy_test for values in(2);
> 
> -- insert enough rows to allow multi-insert into a partitioned table.
> copy (select x,1,'One' from generate_series(1,1000) x
> union all
> select x,2,'two' from generate_series(1001,1010) x
> union all
> select x,1,'One' from generate_series(1011,1020) x) to
> '/tmp/multi_insert_data.csv';
> 
> -- create before insert row trigger on part_copy_test_a2
> create function part_ins_func() returns trigger language plpgsql as
> $$
> begin
>   return new;
> end;
> $$;
> 
> create trigger part_ins_trig before insert on part_copy_test_a2
> for each row execute procedure part_ins_func();
> 
> -- run copy command on partitioned table.
> copy part_copy_test from '/tmp/multi_insert_data.csv';
> 
> postgres=# copy part_copy_test from '/tmp/multi_insert_data.csv';
> server closed the connection unexpectedly
> This probably means the server terminated abnormally
> before or while processing the request.
> The connection to the server was lost. Attempting reset: Failed.
> !>
> 
> I've spent some time looking into this issue and found that,
> CopyFrom() is trying perform multi-insert for the partition that has
> before insert row trigger created on it which is not expected. When a
> normal table with before insert row trigger is created, CopyFrom
> doesn't allow multi insert on such tables and i guess same should be
> the case with table partition as well. Please correct me if i my
> understanding is wrong ?

Yea, that anlysis sounds right. Peter?

Greetings,

Andres Freund


pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: AllocSetContextCreate changes breake extensions
Next
From: Andres Freund
Date:
Subject: CopyFrom() has become way too complicated