postgresql/src/include/access
Tom Lane 942cc240f9 Rethink handling of [Prevent|Is]InTransactionBlock in pipeline mode.
Commits f92944137 et al. made IsInTransactionBlock() set the
XACT_FLAGS_NEEDIMMEDIATECOMMIT flag before returning "false",
on the grounds that that kept its API promises equivalent to those of
PreventInTransactionBlock().  This turns out to be a bad idea though,
because it allows an ANALYZE in a pipelined series of commands to
cause an immediate commit, which is unexpected.

Furthermore, if we return "false" then we have another issue,
which is that ANALYZE will decide it's allowed to do internal
commit-and-start-transaction sequences, thus possibly unexpectedly
committing the effects of previous commands in the pipeline.

To fix the latter situation, invent another transaction state flag
XACT_FLAGS_PIPELINING, which explicitly records the fact that we
have executed some extended-protocol command and not yet seen a
commit for it.  Then, require that flag to not be set before allowing
InTransactionBlock() to return "false".

Having done that, we can remove its setting of NEEDIMMEDIATECOMMIT
without fear of causing problems.  This means that the API guarantees
of IsInTransactionBlock now diverge from PreventInTransactionBlock,
which is mildly annoying, but it seems OK given the very limited usage
of IsInTransactionBlock.  (In any case, a caller preferring the old
behavior could always set NEEDIMMEDIATECOMMIT for itself.)

For consistency also require XACT_FLAGS_PIPELINING to not be set
in PreventInTransactionBlock.  This too is meant to prevent commands
such as CREATE DATABASE from silently committing previous commands
in a pipeline.

Per report from Peter Eisentraut.  As before, back-patch to all
supported branches (which sadly no longer includes v10).

Discussion: https://postgr.es/m/65a899dd-aebc-f667-1d0a-abb89ff3abf8@enterprisedb.com
2022-12-13 14:23:59 -05:00
..
amapi.h Implement operator class parameters 2020-03-30 19:17:23 +03:00
amvalidate.h Implement operator class parameters 2020-03-30 19:17:23 +03:00
attmap.h Fix assorted typos 2020-03-31 16:00:06 +02:00
attnum.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_internal.h Implement operator class parameters 2020-03-30 19:17:23 +03:00
brin_page.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_pageops.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_revmap.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_tuple.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_xlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
bufmask.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
clog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
commit_ts.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
detoast.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
genam.h Implement operator class parameters 2020-03-30 19:17:23 +03:00
generic_xlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
gin.h Implement operator class parameters 2020-03-30 19:17:23 +03:00
gin_private.h Avoid full scan of GIN indexes when possible 2020-01-18 01:11:39 +03:00
ginblock.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
ginxlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
gist.h Implement operator class parameters 2020-03-30 19:17:23 +03:00
gist_private.h Skip WAL for new relfilenodes, under wal_level=minimal. 2020-04-04 12:25:34 -07:00
gistscan.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
gistxlog.h Skip WAL for new relfilenodes, under wal_level=minimal. 2020-04-04 12:25:34 -07:00
hash.h Get rid of trailing semicolons in C macro definitions. 2020-05-01 17:28:00 -04:00
hash_xlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
heapam.h Prevent access to no-longer-pinned buffer in heapam_tuple_lock(). 2022-04-13 13:35:02 -04:00
heapam_xlog.h C comment: remove mention of use of t_hoff WAL structure member 2020-08-31 17:51:31 -04:00
heaptoast.h tableam: New callback relation_fetch_toast_slice. 2020-01-07 14:36:38 -05:00
hio.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
htup.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
htup_details.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
itup.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
multixact.h Rename SLRU structures and associated LWLocks. 2020-05-15 14:28:25 -04:00
nbtree.h Fix deduplication "single value" strategy bug. 2020-06-19 08:57:23 -07:00
nbtxlog.h Adjust "root of to-be-deleted subtree" function. 2020-05-11 11:01:07 -07:00
parallel.h Allow vacuum command to process indexes in parallel. 2020-01-20 07:57:49 +05:30
printsimple.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
printtup.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
relation.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
reloptions.h Implement operator class parameters 2020-03-30 19:17:23 +03:00
relscan.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
rewriteheap.h Skip WAL for new relfilenodes, under wal_level=minimal. 2020-04-04 12:25:34 -07:00
rmgr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
rmgrlist.h Add deduplication to nbtree. 2020-02-26 13:05:30 -08:00
sdir.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
session.h Fix typo. 2020-01-13 14:44:55 +05:30
skey.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
slru.h Prevent excess SimpleLruTruncate() deletion. 2021-01-16 12:21:38 -08:00
spgist.h Implement operator class parameters 2020-03-30 19:17:23 +03:00
spgist_private.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
spgxlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
stratnum.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
subtrans.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
sysattr.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
table.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tableam.h Fix comments related to table AMs 2020-07-14 13:17:31 +09:00
timeline.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
toast_helper.h Introduce macros for typalign and typstorage constants. 2020-03-04 10:34:25 -05:00
toast_internals.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
transam.h Rename SLRU structures and associated LWLocks. 2020-05-15 14:28:25 -04:00
tsmapi.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tupconvert.h Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:55 +02:00
tupdesc.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tupdesc_details.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tupmacs.h Introduce macros for typalign and typstorage constants. 2020-03-04 10:34:25 -05:00
twophase.h Fix CREATE INDEX CONCURRENTLY for the newest prepared transactions. 2021-10-23 18:36:42 -07:00
twophase_rmgr.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
valid.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
visibilitymap.h Split macros from visibilitymap.h into a separate header 2021-09-23 20:12:25 +03:00
visibilitymapdefs.h Split macros from visibilitymap.h into a separate header 2021-09-23 20:12:25 +03:00
xact.h Rethink handling of [Prevent|Is]InTransactionBlock in pipeline mode. 2022-12-13 14:23:59 -05:00
xlog.h Revert "Avoid creating archive status ".ready" files too early" 2021-09-04 12:14:30 -04:00
xlog_internal.h Fix WAL replay in presence of an incomplete record 2021-09-29 11:21:51 -03:00
xlogarchive.h Move routine definitions of xlogarchive.c to a new header file 2020-03-31 15:33:04 +09:00
xlogdefs.h Revert "Avoid creating archive status ".ready" files too early" 2021-09-04 12:14:30 -04:00
xloginsert.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
xlogreader.h Fix WAL replay in presence of an incomplete record 2021-09-29 11:21:51 -03:00
xlogrecord.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
xlogutils.h Revert "Fix replay of create database records on standby" 2022-03-29 15:36:21 +02:00