pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allow "internal" subtransactions in parallel mode.
Date: Thu, 28 Mar 2024 16:43:21 +0000
Message-ID: <E1rpsqX-006Bk9-Eb@gemulon.postgresql.org> (raw)

Allow "internal" subtransactions in parallel mode.

Allow use of BeginInternalSubTransaction() in parallel mode, so long
as the subtransaction doesn't attempt to acquire an XID or increment
the command counter.  Given those restrictions, the other parallel
processes don't need to know about the subtransaction at all, so
this should be safe.  The benefit is that it allows subtransactions
intended for error recovery, such as pl/pgsql exception blocks,
to be used in PARALLEL SAFE functions.

Another reason for doing this is that the API of
BeginInternalSubTransaction() doesn't allow reporting failure.
pl/python for one, and perhaps other PLs, copes very poorly with an
error longjmp out of BeginInternalSubTransaction().  The headline
feature of this patch removes the only easily-triggerable failure
case within that function.  There remain some resource-exhaustion
and similar cases, which we now deal with by promoting them to FATAL
errors, so that callers need not try to clean up.  (It is likely
that such errors would leave us with corrupted transaction state
inside xact.c, making recovery difficult if not impossible anyway.)

Although this work started because of a report of a pl/python crash,
we're not going to do anything about that in the back branches.
Back-patching this particular fix is obviously not very wise.
While we could contemplate some narrower band-aid, pl/python is
already an untrusted language, so it seems okay to classify this
as a "so don't do that" case.

Patch by me, per report from Hao Zhang.  Thanks to Robert Haas for
review.

Discussion: https://postgr.es/m/CALY6Dr-2yLVeVPhNMhuBnRgOZo1UjoTETgtKBx1B2gUi8yy+3g@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0075d78947e3800c5a807f48fd901f16db91101b

Modified Files
--------------
doc/src/sgml/parallel.sgml                 |   8 +-
doc/src/sgml/ref/create_function.sgml      |  20 ++--
src/backend/access/transam/README.parallel |  14 +--
src/backend/access/transam/parallel.c      |   8 +-
src/backend/access/transam/xact.c          | 162 ++++++++++++++++++-----------
src/test/regress/expected/plpgsql.out      |  33 +++++-
src/test/regress/sql/plpgsql.sql           |  24 ++++-
7 files changed, 181 insertions(+), 88 deletions(-)



Message-ID: <E1rpsqX-006Bk9-Eb@gemulon.postgresql.org>
Permalink:  ../E1rpsqX-006Bk9-Eb@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1rpsqX-006Bk9-Eb@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Allow "internal" subtransactions in parallel mode.
  In-Reply-To: <E1rpsqX-006Bk9-Eb@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox