Re: assessing parallel-safety - Mailing list pgsql-hackers

From Robert Haas
Subject Re: assessing parallel-safety
Date
Msg-id CA+TgmoaVaic0Wq4TF9o7j7dOjedyboWowbLJJF_LSi+yr91gHw@mail.gmail.com
Whole thread Raw
In response to Re: assessing parallel-safety  (Noah Misch <noah@leadboat.com>)
Responses Re: assessing parallel-safety  (Noah Misch <noah@leadboat.com>)
List pgsql-hackers
On Fri, Feb 13, 2015 at 12:10 AM, Noah Misch <noah@leadboat.com> wrote:
> Given your wish to optimize, I recommend first investigating the earlier
> thought to issue eval_const_expressions() once per planner() instead of once
> per subquery_planner().  Compared to the parallelModeRequired/parallelModeOK
> idea, it would leave us with a more maintainable src/backend/optimizer.  I
> won't object to either design, though.

In off-list discussions with Tom Lane, he pressed hard on the question
of whether we can zero out the number of functions that are
parallel-unsafe (i.e. can't be run while parallel even in the master)
vs. parallel-restricted (must be run in the master rather than
elsewhere).  The latter category can be handled by strictly local
decision-making, without needing to walk the entire plan tree; e.g.
parallel seq scan can look like this:

Parallel Seq Scan on foo  Filter: a = pg_backend_pid()  Parallel Filter: b = 1

And, indeed, I was pleasantly surprised when surveying the catalogs by
how few functions were truly unsafe, vs. merely needing to be
restricted to the master.  But I can't convince myself that there's
any way sane of allowing database writes even in the master; creating
new combo CIDs there seems disastrous, and users will be sad if a
parallel plan is chosen for some_plpgsql_function_that_does_updates()
and this then errors out because of parallel mode.

Tom also argued that (1) trying to assess parallel-safety before
preprocess_expressions() was doomed to fail, because
preprocess_expressions() can additional function calls via, at least,
inlining and default argument insertion and (2)
preprocess_expressions() can't be moved earlier than without changing
the semantics.  I'm not sure if he's right, but those are sobering
conclusions.  Andres pointed out to me via IM that inlining is
dismissable here; if inlining introduces a parallel-unsafe construct,
the inlined function was mislabeled to begin with, and the user has
earned the error message they get.  Default argument insertion might
not be dismissable although the practical risks seem low.

It's pretty awful that this is such a thorny issue, and the patch may
be rather cringe-worthy, given the (to me) essentially reasonable
nature of wanting to know whether a query has any references to a
function with a certain property in it.

> Your survey of parallel safety among built-in functions was on-target.

Thanks for having a look.   A healthy amount of the way the parallel
mode stuff works came from your brain, so your opinion, while always
valuable, is especially appreciated here.  I have a lot of confidence
in your judgement about this stuff.

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



pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: SSL renegotiation and other related woes
Next
From: Robert Haas
Date:
Subject: Re: question on Postgres smart shutdown mode