postgresql/src/backend
Michael Paquier d0eb4297cc Handle better implicit transaction state of pipeline mode
When using a pipeline, a transaction starts from the first command and
is committed with a Sync message or when the pipeline ends.

Functions like IsInTransactionBlock() or PreventInTransactionBlock()
were already able to understand a pipeline as being in a transaction
block, but it was not the case of CheckTransactionBlock().  This
function is called for example to generate a WARNING for SET LOCAL,
complaining that it is used outside of a transaction block.

The current state of the code caused multiple problems, like:
- SET LOCAL executed at any stage of a pipeline issued a WARNING, even
if the command was at least second in line where the pipeline is in a
transaction state.
- LOCK TABLE failed when invoked at any step of a pipeline, even if it
should be able to work within a transaction block.

The pipeline protocol assumes that the first command of a pipeline is
not part of a transaction block, and that any follow-up commands is
considered as within a transaction block.

This commit changes the backend so as an implicit transaction block is
started each time the first Execute message of a pipeline has finished
processing, with this implicit transaction block ended once a sync is
processed.  The checks based on XACT_FLAGS_PIPELINING in the routines
checking if we are in a transaction block are not necessary: it is
enough to rely on the existing ones.

Some tests are added to pgbench, that can be backpatched down to v17
when \syncpipeline is involved and down to v14 where \startpipeline and
\endpipeline are available.  This is unfortunately limited regarding the
error patterns that can be checked, but it provides coverage for various
pipeline combinations to check if these succeed or fail.  These tests
are able to capture the case of SET LOCAL's WARNING.  The author has
proposed a different feature to improve the coverage by adding similar
meta-commands to psql where error messages could be checked, something
more useful for the cases where commands cannot be used in transaction
blocks, like REINDEX CONCURRENTLY or VACUUM.  This is considered as
future work for v18~.

Author: Anthonin Bonnefoy
Reviewed-by: Jelte Fennema-Nio, Michael Paquier
Discussion: https://postgr.es/m/CAO6_XqrWO8uNBQrSu5r6jh+vTGi5Oiyk4y8yXDORdE2jbzw8xw@mail.gmail.com
Backpatch-through: 13
2024-11-27 09:31:22 +09:00
..
access Handle better implicit transaction state of pipeline mode 2024-11-27 09:31:22 +09:00
archive Apply more quoting to GUC names in messages 2024-09-04 13:50:44 +09:00
backup Clean up newlines following left parentheses 2024-11-26 17:10:07 +01:00
bootstrap Assign a child slot to every postmaster child process 2024-11-14 16:12:28 +02:00
catalog Proper object locking for GRANT/REVOKE 2024-11-15 11:03:48 +01:00
commands pgindent run 2024-11-21 21:40:17 +01:00
executor Fix NULLIF()'s handling of read-write expanded objects. 2024-11-25 18:09:09 -05:00
foreign Improve style of two code paths 2024-10-08 10:51:20 +09:00
jit Fix NULLIF()'s handling of read-write expanded objects. 2024-11-25 18:09:09 -05:00
lib Revert pg_wal_replay_wait() stored procedure 2024-11-04 22:47:57 +02:00
libpq Remove unused #include's from backend .c files 2024-10-27 08:26:50 +01:00
main Remove unused #include's from backend .c files 2024-10-27 08:26:50 +01:00
nodes Add pg_constraint rows for not-null constraints 2024-11-08 13:28:48 +01:00
optimizer Remove dead code in get_param_path_clause_serials() 2024-11-26 09:27:53 +09:00
parser Add pg_constraint rows for not-null constraints 2024-11-08 13:28:48 +01:00
partitioning Revert support for ALTER TABLE ... MERGE/SPLIT PARTITION(S) commands 2024-08-24 18:48:48 +03:00
po Translation updates 2024-06-24 13:11:27 +02:00
port Require memory barrier support. 2024-07-30 23:01:55 +12:00
postmaster Pass MyPMChildSlot as an explicit argument to child process 2024-11-14 16:12:32 +02:00
regex Avoid assertion due to disconnected NFA sub-graphs in regex parsing. 2024-11-15 18:23:38 -05:00
replication Doc: Clarify the inactive_since field description. 2024-11-25 11:12:32 +05:30
rewrite Ensure cached plans are correctly marked as dependent on role. 2024-11-11 09:00:00 -06:00
snowball Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
statistics Disallow modifying statistics on system columns. 2024-11-22 12:40:24 -08:00
storage Distinguish between AcquireExternalFD and epoll_create1 / kqueue failing 2024-11-26 12:44:47 -05:00
tcop Handle better implicit transaction state of pipeline mode 2024-11-27 09:31:22 +09:00
tsearch Constify fields and parameters in spell.c 2024-08-06 23:04:51 +03:00
utils Clean up newlines following left parentheses 2024-11-26 17:10:07 +01:00
.gitignore
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Fix make build on MinGW 2024-06-21 08:17:23 +02:00
meson.build meson: Fix import library name in Windows 2024-06-20 09:08:36 +02:00
nls.mk Add missing gettext triggers 2024-05-14 12:57:22 +02:00