Re: assessing parallel-safety

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: Thom Brown <thom(at)linux(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Noah Misch <noah(at)leadboat(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: assessing parallel-safety
Date: 2015-07-15 20:32:23
Message-ID: CA+TgmoZYxoO3V0_dkLSCQeyes5sdbkOcVj1uyKLfY05YZY96NQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jul 15, 2015 at 1:50 AM, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
> One issue which I think we should fix in this patch as pointed earlier
> is, in some cases, Function containing Select stmt won't be able to
> use parallel plan even though it is marked as parallel safe.
>
> create or replace function parallel_func_select() returns integer
> as $$
> declare
> ret_val int;
> begin
> Select c1 into ret_val from t1 where c1 = 1;
> return ret_val;
> end;
> $$ language plpgsql Parallel Safe;
>
> Above function won't be able to use parallel plan for Select statement
> because of below code:
>
> static int
> exec_stmt_execsql(PLpgSQL_execstate *estate,
> PLpgSQL_stmt_execsql
> *stmt)
> {
> ..
> if (expr->plan == NULL)
> {
> ..
> exec_prepare_plan(estate, expr, 0);
> }
> ..
> }
>
> As the cursorOptions passed in this function are always 0, planner
> will treat it as unsafe function. Shouldn't we need to check parallelOk
> to pass cursoroption in above function as is done in exec_run_select()
> in patch?

exec_stmt_execsql is called by exec_stmt_open and exec_stmt_forc.
Those are cursor operations and thus - I think - parallelism can't be
used there. I think it would be OK to enable parallelism when we are
using it to execute a toplevel SQL statement, but I didn't do it
because I wasn't entirely sure that we couldn't pass the same
stmt->sqlstmt into exec_stmt_execsql from multiple contexts, some of
which are parallel-safe and others not. I don't think that can
happen, but my understanding of PL/pgsql is not the greatest.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Christensen 2015-07-15 21:18:06 [PATCH] Comment fix for miscinit.c
Previous Message Rahila Syed 2015-07-15 20:18:44 Re: [PROPOSAL] VACUUM Progress Checker.