postgresql/src
Tom Lane c96de42c4b Further refine _SPI_execute_plan's rule for atomic execution.
Commit 2dc1deaea turns out to have been still a brick shy of a load,
because CALL statements executing within a plpgsql exception block
could still pass the wrong snapshot to stable functions within the
CALL's argument list.  That happened because standard_ProcessUtility
forces isAtomicContext to true if IsTransactionBlock is true, which
it always will be inside a subtransaction.  Then ExecuteCallStmt
would think it does not need to push a new snapshot --- but
_SPI_execute_plan didn't do so either, since it thought it was in
nonatomic mode.

The best fix for this seems to be for _SPI_execute_plan to operate
in atomic execution mode if IsSubTransaction() is true, even when the
SPI context as a whole is non-atomic.  This makes _SPI_execute_plan
have the same rules about when non-atomic execution is allowed as
_SPI_commit/_SPI_rollback have about when COMMIT/ROLLBACK are allowed,
which seems appropriately symmetric.  (If anyone ever tries to allow
COMMIT/ROLLBACK inside a subtransaction, this would all need to be
rethought ... but I'm unconvinced that such a thing could be logically
consistent at all.)

For further consistency, also check IsSubTransaction() in
SPI_inside_nonatomic_context.  That does not matter for its
one present-day caller StartTransaction, which can't be reached
inside a subtransaction.  But if any other callers ever arise,
they'd presumably want this definition.

Per bug #18656 from Alexander Alehin.  Back-patch to all
supported branches, like previous fixes in this area.

Discussion: https://postgr.es/m/18656-cade1780866ef66c@postgresql.org
2024-10-16 17:36:40 -04:00
..
backend Further refine _SPI_execute_plan's rule for atomic execution. 2024-10-16 17:36:40 -04:00
bin initdb: Change default to using data checksums. 2024-10-16 08:48:10 +02:00
common Whitespace fixup from generated unicode tables. 2024-10-16 12:21:13 -07:00
fe_utils pg_verifybackup: Verify tar-format backups. 2024-09-27 08:40:24 -04:00
include Normalize nbtree truncated high key array behavior. 2024-10-16 12:17:49 -04:00
interfaces ecpg: fix some minor mishandling of bad input in preprocessor. 2024-10-16 12:25:00 -04:00
makefiles Add -Wmissing-variable-declarations to the standard compilation flags 2024-08-03 11:51:02 +02:00
pl Further refine _SPI_execute_plan's rule for atomic execution. 2024-10-16 17:36:40 -04:00
port Simplify checking for xlocale.h 2024-10-01 07:23:45 -04:00
template thread-safety: gmtime_r(), localtime_r() 2024-08-23 07:43:04 +02:00
test Allow TAP tests to force checksums off when calling init() 2024-10-14 11:25:03 +02:00
timezone Update time zone data files to tzdata release 2024a. 2024-02-01 15:57:53 -05:00
tools ecpg: improve preprocessor's memory management. 2024-10-14 13:55:08 -04:00
tutorial Update copyright for 2024 2024-01-03 20:49:05 -05:00
.gitignore
DEVELOPERS
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
Makefile.global.in Add -Wmissing-variable-declarations to the standard compilation flags 2024-08-03 11:51:02 +02:00
Makefile.shlib Remove AIX support 2024-02-28 15:17:23 +04:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
nls-global.mk Remove distprep 2023-11-06 15:18:04 +01:00