Re: [HACKERS] Request more documentation for incompatibility ofparallelism and plpgsql exec_run_select - Mailing list pgsql-hackers

From Amit Kapila
Subject Re: [HACKERS] Request more documentation for incompatibility ofparallelism and plpgsql exec_run_select
Date
Msg-id CAA4eK1K71TKr42_Nen7Z_U_MqxzeU-nHmb3jWgvS1+Pd3NHz6A@mail.gmail.com
Whole thread Raw
In response to [HACKERS] Request more documentation for incompatibility of parallelism and plpgsql exec_run_select  (Mark Dilger <hornschnorter@gmail.com>)
Responses Re: [HACKERS] Request more documentation for incompatibility of parallelism and plpgsql exec_run_select  (Mark Dilger <hornschnorter@gmail.com>)
Re: [HACKERS] Request more documentation for incompatibility ofparallelism and plpgsql exec_run_select  (Simon Riggs <simon@2ndquadrant.com>)
List pgsql-hackers
On Fri, Jun 30, 2017 at 9:25 AM, Mark Dilger <hornschnorter@gmail.com> wrote:
> Hackers,
>
> In src/pl/plpgsql/src/pl_exec.c: exec_run_select intentionally does not
> allow a parallel plan if a portal will be returned.  This has the practical
> consequence that a common coding practice (at least for me) of doing
> something like:
>
> create function myfunc(arg1 text, arg2 text) returns setof myfunctype as $$
> declare
>         sql             text;
>         result  myfunctype;
> begin
>         -- unsafe interpolation, but this is just a code example
>         sql := 'select foo from bar where a = ' || arg1 || ' and b = ' || arg2;
>         for result in execute sql loop
>                 return next result;
>         end loop;
>         return;
> end;
> $$ language plpgsql volatile;
>
> can't run the generated 'sql' in parallel.  I think this is understandable, but
> the documentation of this limitation in the sgml docs is thin.  Perhaps
> someone who understands this limitation better than I do can document it?
>

This is explained in section 15.2 [1], refer below para:
"The query might be suspended during execution. In any situation in
which the system thinks that partial or incremental execution might
occur, no parallel plan is generated. For example, a cursor created
using DECLARE CURSOR will never use a parallel plan. Similarly, a
PL/pgSQL loop of the form FOR x IN query LOOP .. END LOOP will never
use a parallel plan, because the parallel query system is unable to
verify that the code in the loop is safe to execute while parallel
query is active."

Check if that clarifies your doubts, otherwise, we might need to write
something more so that it can be easier for users to understand.

[1] - https://www.postgresql.org/docs/devel/static/when-can-parallel-query-be-used.html



-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Mark Dilger
Date:
Subject: [HACKERS] Request more documentation for incompatibility of parallelism and plpgsql exec_run_select
Next
From: Alvaro Herrera
Date:
Subject: Re: [HACKERS] Race conditions with WAL sender PID lookups