pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m 6+ messages / 1 participants [nested] [flat]
* pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m @ 2022-12-13 19:24 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2022-12-13 19:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/942cc240f95998793e10156952c14961b5559b2a Modified Files -------------- doc/src/sgml/protocol.sgml | 9 +++++---- src/backend/access/transam/xact.c | 28 ++++++++++++++++++---------- src/backend/tcop/postgres.c | 12 ++++++++++++ src/include/access/xact.h | 7 +++++++ 4 files changed, 42 insertions(+), 14 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m @ 2022-12-13 19:24 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2022-12-13 19:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/18431ee6f511be0c4cf4d7463899ce318c7632eb Modified Files -------------- doc/src/sgml/libpq.sgml | 5 +++-- doc/src/sgml/protocol.sgml | 9 +++++---- src/backend/access/transam/xact.c | 28 ++++++++++++++++++---------- src/backend/tcop/postgres.c | 12 ++++++++++++ src/include/access/xact.h | 7 +++++++ 5 files changed, 45 insertions(+), 16 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m @ 2022-12-13 19:24 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2022-12-13 19:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/20432f8731404d2cef2a155144aca5ab3ae98e95 Modified Files -------------- doc/src/sgml/libpq.sgml | 5 +++-- doc/src/sgml/protocol.sgml | 9 +++++---- src/backend/access/transam/xact.c | 28 ++++++++++++++++++---------- src/backend/tcop/postgres.c | 12 ++++++++++++ src/include/access/xact.h | 7 +++++++ 5 files changed, 45 insertions(+), 16 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m @ 2022-12-13 19:24 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2022-12-13 19:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/1cca4a75ffb82c7e0497e6195b7fb3ed44dc430e Modified Files -------------- doc/src/sgml/protocol.sgml | 9 +++++---- src/backend/access/transam/xact.c | 28 ++++++++++++++++++---------- src/backend/tcop/postgres.c | 12 ++++++++++++ src/include/access/xact.h | 7 +++++++ 4 files changed, 42 insertions(+), 14 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m @ 2022-12-13 19:24 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2022-12-13 19:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/f48aa5df4e030ab75bdc2ca5fc480c4a830cf5f3 Modified Files -------------- doc/src/sgml/protocol.sgml | 9 +++++---- src/backend/access/transam/xact.c | 28 ++++++++++++++++++---------- src/backend/tcop/postgres.c | 12 ++++++++++++ src/include/access/xact.h | 7 +++++++ 4 files changed, 42 insertions(+), 14 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m @ 2022-12-13 19:24 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2022-12-13 19:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ae47f8a9664a65b233ee3c716f3098a5ba71f615 Modified Files -------------- doc/src/sgml/libpq.sgml | 5 +++-- doc/src/sgml/protocol.sgml | 9 +++++---- src/backend/access/transam/xact.c | 28 ++++++++++++++++++---------- src/backend/tcop/postgres.c | 12 ++++++++++++ src/include/access/xact.h | 7 +++++++ 5 files changed, 45 insertions(+), 16 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2022-12-13 19:24 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2022-12-13 19:24 pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m Tom Lane <tgl@sss.pgh.pa.us> 2022-12-13 19:24 pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m Tom Lane <tgl@sss.pgh.pa.us> 2022-12-13 19:24 pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m Tom Lane <tgl@sss.pgh.pa.us> 2022-12-13 19:24 pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m Tom Lane <tgl@sss.pgh.pa.us> 2022-12-13 19:24 pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m Tom Lane <tgl@sss.pgh.pa.us> 2022-12-13 19:24 pgsql: Rethink handling of [Prevent|Is]InTransactionBlock in pipeline m Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox