Re: COPY (query) TO ... doesn't allow parallelism

From: Andres Freund <andres(at)anarazel(dot)de>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY (query) TO ... doesn't allow parallelism
Date: 2017-06-03 16:04:26
Message-ID: 20170603160426.inui2y67hltddhgw@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2017-06-03 17:40:08 +0530, Amit Kapila wrote:
> The standard_planner check is sufficient to not generate parallel
> plans for such statements, but it won't prevent if such commands
> (which shouldn't be executed by parallel workers) are present in
> functions. Consider a hypothetical case as below:
>
> 1. Create a parallel safe function containing Copy commands.
> create or replace function parallel_copy(a integer) returns integer
> as $$
> begin
> Copy (select * from t1 where c1 < 2) to 'e:\\f1';
> return a;
> end;
> $$ language plpgsql Parallel Safe;
>
> 2. Now use this in some command which can be executed in parallel.
> explain analyze select * from t1 where c1 < parallel_copy(10);
>
> This can allow Copy command to be executed by parallel workers if we
> don't have sufficient safeguards.

Yes. But I'm unclear what does that have to do with the change
discussed in this thread? The pg_plan_query in copy.c setting
CURSOR_OPT_PARALLEL_OK doesn't meaningfully change the risk of this
happening in one way or the other.

> We already tried to prohibit it in
> plpgsql like in function _SPI_execute_plan(), we call
> PreventCommandIfParallelMode. However, inspite of that, we have
> safeguards in lower level calls, so that if the code flow reaches such
> commands in parallel mode, we error out. We have a similar check in
> Copy From code flow ( PreventCommandIfParallelMode("COPY FROM");) as
> well, but I think we should have it in Copy To flow as well.

Why? What is it effectively preventing? Multiple workers copying to
the same file? Any such function would have the same risk for separate
sessions.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2017-06-03 16:53:51 Re: Get stuck when dropping a subscription during synchronizing table
Previous Message Dang Minh Huong 2017-06-03 15:43:17 Re: Extra Vietnamese unaccent rules