Re: Multi-insert into a partitioned table with before insert row trigger causes server crash on latest HEAD

From: Andres Freund <andres(at)anarazel(dot)de>
To: Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Multi-insert into a partitioned table with before insert row trigger causes server crash on latest HEAD
Date: 2018-10-12 18:00:07
Message-ID: 20181012180007.zn2u6hkac5blwrzs@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2018-10-12 18:13:37 CopyFrom() has become way too complicated
Previous Message Andres Freund 2018-10-12 17:56:55 Re: AllocSetContextCreate changes breake extensions