Re: Lifespan of a BeginInternalSubTransaction subxact ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chapman Flack <chap(at)anastigmatix(dot)net>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Lifespan of a BeginInternalSubTransaction subxact ?
Date: 2019-03-16 01:20:03
Message-ID: 20880.1552699203@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Chapman Flack <chap(at)anastigmatix(dot)net> writes:
> 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?

Sounds about right, though I haven't checked the details exactly.

> 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.

Yup.

> 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;

When control returns from a function, we resume executing the statement
that called it. This can *not* be in a different (sub)transaction than
the statement started in; that wouldn't make any sense logically, and
it certainly won't work from an implementation standpoint either.

The rules are laxer for procedures, I believe; at the very least those are
allowed to commit the calling transaction and start a new one. I'm less
sure about how they can interact with subtransactions. To support this,
a CALL statement has to not have any internal state that persists past
the procedure call. But a function cannot expect that the calling
statement lacks internal state.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2019-03-16 01:21:47 Make pg_checksums complain if compiled BLCKSZ and data folder's block size differ
Previous Message David Fetter 2019-03-16 01:18:23 Re: string_to_array, array_to_string function without separator