summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2022-12-13 19:23:59 +0000
committerTom Lane2022-12-13 19:23:59 +0000
commitf48aa5df4e030ab75bdc2ca5fc480c4a830cf5f3 (patch)
treef18972d4a486d07197b7d5fba50d608fb936c502 /src/include
parent990a773ab6a807f3436d86b2825435f1274a8187 (diff)
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
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/xact.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/include/access/xact.h b/src/include/access/xact.h
index bce1bfb4f86..5066587637c 100644
--- a/src/include/access/xact.h
+++ b/src/include/access/xact.h
@@ -112,6 +112,13 @@ extern int MyXactFlags;
#define XACT_FLAGS_NEEDIMMEDIATECOMMIT (1U << 3)
/*
+ * XACT_FLAGS_PIPELINING - set when we complete an extended-query-protocol
+ * Execute message. This is useful for detecting that an implicit transaction
+ * block has been created via pipelining.
+ */
+#define XACT_FLAGS_PIPELINING (1U << 4)
+
+/*
* start- and end-of-transaction callbacks for dynamically loaded modules
*/
typedef enum