Re: Whan is it safe to mark a function PARALLEL SAFE? - Mailing list pgsql-general

From Peter Geoghegan
Subject Re: Whan is it safe to mark a function PARALLEL SAFE?
Date
Msg-id CAH2-WzmO2xg1G80HnBQjZ-YquowQxDR=dXLRynExdgLu3bfxTg@mail.gmail.com
Whole thread Raw
In response to Re: Whan is it safe to mark a function PARALLEL SAFE?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Whan is it safe to mark a function PARALLEL SAFE?
List pgsql-general
On Sun, Sep 8, 2019 at 12:27 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > If an error is raised in one parallel worker, does this
> > cause the other parallel workers to be immediately terminated?
>
> I think not, though I didn't work on that code.  The error will
> be reported to the parent backend, which will cause it to fail
> the query ... but I think it just waits for the other worker
> children to exit first.  That's not something to rely on of course.
> Even if we don't make an attempt to cancel the other workers today
> we probably will in future.  But the cancel attempt would certainly
> be asynchronous, so I'm not sure how "immediate" you are worried
> about it being.

If workers call CHECK_FOR_INTERRUPTS() frequently, which they should,
then it should appear to users as if raising an error in one worker
kills everything almost immediately, or immediately.  For example, if
a parallel CREATE INDEX has a worker that raises a unique violation
error, that must work in a way that at least *appears* to be very
similar to what the user would get with a serial CREATE INDEX. (The
worst that can happen is that they'll very occasionally get two unique
violation errors instead of one, or something like that.)

That said, there are theoretical failures where it could take rather a
long time for the parent/leader to get the memo -- see
WaitForParallelWorkersToAttach() and its caller (note that anything
using a gather node is subject to the same kind of failure that
WaitForParallelWorkersToAttach() handles, even though they won't call
the function themselves). These failures (e.g. fork() failure) are
generally assumed to be rare to non-existent, though. Users will
surely be upset if parallel queries cannot be cancelled almost
immediately. If it happened with any regularity, somebody would have
complained by now.

As Tom said, it's hard to give a useful answer without more context --
how you define "immediate"?

-- 
Peter Geoghegan



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Whan is it safe to mark a function PARALLEL SAFE?
Next
From: Adrian Klaver
Date:
Subject: Re: Convert a row to a nested JSON document containing all relationsin PostgreSQL