postgresql/src/include
Tom Lane 20432f8731 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:58 -05:00
..
access Rethink handling of [Prevent|Is]InTransactionBlock in pipeline mode. 2022-12-13 14:23:58 -05:00
backup Reduce basebackup_sink.h inclusion footprint 2022-10-12 09:42:20 +02:00
bootstrap Harmonize more lexer function parameter names. 2022-09-22 13:27:16 -07:00
catalog Get rid of recursion-marker values in enum AlterTableType 2022-12-12 11:13:26 +01:00
commands Rework query relation permission checking 2022-12-06 16:09:24 +01:00
common Convert json_in and jsonb_in to report errors softly. 2022-12-11 11:28:15 -05:00
datatype Fix overflow hazards in interval input and output conversions. 2022-04-02 16:12:29 -04:00
executor Rework query relation permission checking 2022-12-06 16:09:24 +01:00
fe_utils Revert 56-bit relfilenode change and follow-up commits. 2022-09-28 09:55:28 -04:00
foreign Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
jit Add central declarations for dlsym()ed symbols 2022-07-17 17:23:42 -07:00
lib Fix wording in comment 2022-11-17 13:17:19 +01:00
libpq Rework memory contexts in charge of HBA/ident tokenization 2022-11-24 08:21:55 +09:00
mb Convert json_in and jsonb_in to report errors softly. 2022-12-11 11:28:15 -05:00
nodes Get rid of recursion-marker values in enum AlterTableType 2022-12-12 11:13:26 +01:00
optimizer Rework query relation permission checking 2022-12-06 16:09:24 +01:00
parser Rework query relation permission checking 2022-12-06 16:09:24 +01:00
partitioning Move PartitioPruneInfo out of plan nodes into PlannedStmt 2022-12-01 12:56:21 +01:00
pch meson: Add support for building with precompiled headers 2022-10-06 17:19:30 -07:00
port mingw: Define PGDLLEXPORT as __declspec (dllexport) as done for msvc 2022-09-30 10:50:05 -07:00
portability Fix obsolete comments in instr_time.h. 2022-08-09 11:50:03 +12:00
postmaster Provide options for postmaster to kill child processes with SIGABRT. 2022-11-21 11:59:29 -05:00
regex Consistently use named parameters in regex code. 2022-09-19 15:10:24 -07:00
replication Avoid unnecessary streaming of transactions during logical replication. 2022-12-08 06:05:09 +05:30
rewrite Rework query relation permission checking 2022-12-06 16:09:24 +01:00
snowball Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
statistics Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
storage Update types in File API 2022-12-08 08:58:15 +01:00
tcop Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
tsearch Replace link to Hunspell with the current homepage 2022-11-21 23:25:48 +01:00
utils Convert json_in and jsonb_in to report errors softly. 2022-12-11 11:28:15 -05:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
c.h Make AssertPointerAlignment available to frontend code 2022-11-03 12:04:22 -04:00
fmgr.h Convert json_in and jsonb_in to report errors softly. 2022-12-11 11:28:15 -05:00
funcapi.h Remove compatibility declarations for InitMaterializedSRF() 2022-10-18 10:44:02 +09:00
getopt_long.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
Makefile Move gramparse.h to src/backend/parser 2022-09-14 10:57:13 +07:00
meson.build meson: Add basic PGXS compatibility 2022-12-06 18:56:46 -08:00
miscadmin.h Remove AssertArg and AssertState 2022-10-28 09:19:06 +02:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.meson meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
pg_config_manual.h Remove our artificial PG_SOMAXCONN limit on listen queue length. 2022-08-23 10:15:06 -04:00
pg_config.h.in Remove configure probe for sockaddr_in6 and require AF_INET6. 2022-08-26 10:18:30 +12:00
pg_getopt.h Apply PGDLLIMPORT markings broadly. 2022-04-08 08:16:38 -04:00
pg_trace.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
pgstat.h Generate pg_stat_get*() functions for databases using macros 2022-12-07 09:11:48 +09:00
pgtar.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
pgtime.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
port.h pg_basebackup: Fix cross-platform tablespace relocation. 2022-10-21 08:21:55 -04:00
postgres_ext.h Move RelFileNumber declarations to common/relpath.h. 2022-09-27 12:01:57 -04:00
postgres_fe.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
postgres.h Simplify our Assert infrastructure a little. 2022-10-10 15:16:56 -04:00
windowapi.h Update copyright for 2022 2022-01-07 19:04:57 -05:00