Lifespan of a BeginInternalSubTransaction subxact ?

From: Chapman Flack <chap(at)anastigmatix(dot)net>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Lifespan of a BeginInternalSubTransaction subxact ?
Date: 2019-03-16 01:06:22
Message-ID: 5C8C4C0E.3080201@anastigmatix.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

PL/Java implements JDBC Savepoints using BeginInternalSubTransaction/
ReleaseCurrentSubTransaction/RollbackAndReleaseCurrentSubTransaction.

That seems to be the Accepted Way of Doing Things within backend PLs
that want control over error recovery, am I right?

PL/Java also strictly enforces that such a subxact set within a Java
function must be released or rolled back by the time that function
returns.

The reasoning there is less obvious to me; my intuition would have been
that a subtransaction could remain in play for the life of its containing
transaction, which could have been started outside of this Java function;
by holding a reference to the JDBC Savepoint object, a later Java function
called in the same transaction could release it or roll it back.

But I am beginning to suspect that the limitation may be essential, given
the comments in xact.c around StartSubTransaction and how its effects would
get clobbered on exit from a Portal, so a subxact started by an actual
SAVEPOINT is started in two steps, the later one after the Portal has
exited. By contrast, within a function (being executed inside a Portal?),
I have to use BeginInternalSubTransaction, which combines the multiple steps
into one, but whose effects wouldn't survive the exit of the Portal.

Have I reverse-engineered this reasoning correctly? If so, I'll add some
comments about it in the PL/Java code where somebody may be thankful for
them later.

Or, if it turns out the limitation isn't so inescapable, and could be
relaxed to allow a subxact lifetime longer than the single function that
starts it, I could look into doing that.

Thanks!
-Chap

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Fetter 2019-03-16 01:18:23 Re: string_to_array, array_to_string function without separator
Previous Message Tomas Vondra 2019-03-15 22:05:28 Re: seems like a bug in pgbench -R