postgresql/src/include/access
Tom Lane 1cca4a75ff 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 Initial pgindent run for v12. 2019-05-22 12:55:34 -04:00
amvalidate.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
attnum.h Fix many typos and inconsistencies 2019-07-01 10:00:23 +09:00
brin.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
brin_internal.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
brin_page.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
brin_pageops.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
brin_revmap.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
brin_tuple.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
brin_xlog.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
bufmask.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
clog.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
commit_ts.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
genam.h Improve handling of NULLs in KNN-GiST and KNN-SP-GiST 2019-09-19 21:49:07 +03:00
generic_xlog.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
gin.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
gin_private.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
ginblock.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
ginxlog.h Generate less WAL during GiST, GIN and SP-GiST index build. 2019-04-03 17:03:15 +03:00
gist.h Use full 64-bit XID for checking if a deleted GiST page is old enough. 2019-07-24 20:25:22 +03:00
gist_private.h Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:13 -07:00
gistscan.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
gistxlog.h Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:13 -07:00
hash.h Get rid of trailing semicolons in C macro definitions. 2020-05-01 17:28:00 -04:00
hash_xlog.h Compute XID horizon for page level index vacuum on primary. 2019-03-26 16:52:54 -07: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
hio.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
htup.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
htup_details.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
itup.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
multixact.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
nbtree.h Get rid of trailing semicolons in C macro definitions. 2020-05-01 17:28:00 -04:00
nbtxlog.h Fix nbtree page split rmgr desc routine. 2019-09-12 15:45:07 -07:00
parallel.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
printsimple.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
printtup.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
relation.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
reloptions.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
relscan.h Initial pgindent run for v12. 2019-05-22 12:55:34 -04:00
rewriteheap.h Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:13 -07:00
rmgr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
rmgrlist.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
sdir.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
session.h Fix typo. 2020-01-13 14:52:59 +05:30
skey.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
slru.h Prevent excess SimpleLruTruncate() deletion. 2021-01-16 12:21:39 -08:00
spgist.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
spgist_private.h Improve handling of NULLs in KNN-GiST and KNN-SP-GiST 2019-09-19 21:49:07 +03:00
spgxlog.h Initial pgindent run for v12. 2019-05-22 12:55:34 -04:00
stratnum.h Move hash_any prototype from access/hash.h to utils/hashutils.h 2019-03-11 13:17:50 -03:00
subtrans.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
sysattr.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
table.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
tableam.h Fix comments related to table AMs 2020-07-14 13:17:34 +09:00
timeline.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
transam.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
tsmapi.h tableam: sample scan. 2019-03-31 18:37:57 -07:00
tupconvert.h Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:55 +02:00
tupdesc.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
tupdesc_details.h Make naming of tupdesc related structs more consistent with the rest of PG. 2019-01-14 16:25:50 -08:00
tupmacs.h Improve comment for att_isnull. 2019-05-13 13:13:24 -04:00
tuptoaster.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
twophase.h Fix CREATE INDEX CONCURRENTLY for the newest prepared transactions. 2021-10-23 18:36:42 -07:00
twophase_rmgr.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
valid.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
visibilitymap.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04: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
xlogdefs.h Revert "Avoid creating archive status ".ready" files too early" 2021-09-04 12:14:30 -04:00
xloginsert.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
xlogreader.h Fix WAL replay in presence of an incomplete record 2021-09-29 11:21:51 -03:00
xlogrecord.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
xlogutils.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00