diff options
author | Michael Paquier <michael@paquier.xyz> | 2025-02-23 16:43:07 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2025-02-23 16:43:07 +0900 |
commit | a4e986ef5a4698b43a3a9b11791b282734938ed1 (patch) | |
tree | bbdf9b4655d831e272520ac5818f1c88a0b0bf9f /src | |
parent | f98765f0ce90e465e35c809f4b3caaeeb3d24610 (diff) | |
download | postgresql-a4e986ef5a4698b43a3a9b11791b282734938ed1.tar.gz postgresql-a4e986ef5a4698b43a3a9b11791b282734938ed1.zip |
Add more tests for utility commands in pipelines
This commit checks interactions with pipelines and implicit transaction
blocks for the following commands that have their own behaviors when
used in pipelines depending on their order in a pipeline and sync
requests:
- SET LOCAL
- REINDEX CONCURRENTLY
- VACUUM
- Subtransactions (SAVEPOINT, ROLLBACK TO SAVEPOINT)
These scenarios could be tested only with pgbench previously. The
meta-commands of psql controlling pipelines make these easier to
implement, debug, and they can be run in a SQL script.
Author: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Discussion: https://postgr.es/m/CAO6_XqroE7JuMEm1sWz55rp9fAYX2JwmcP_3m_v51vnOFdsLiQ@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r-- | src/test/regress/expected/psql_pipeline.out | 112 | ||||
-rw-r--r-- | src/test/regress/sql/psql_pipeline.sql | 72 |
2 files changed, 184 insertions, 0 deletions
diff --git a/src/test/regress/expected/psql_pipeline.out b/src/test/regress/expected/psql_pipeline.out index bdf5a99d09b..f4603d2b66a 100644 --- a/src/test/regress/expected/psql_pipeline.out +++ b/src/test/regress/expected/psql_pipeline.out @@ -585,5 +585,117 @@ PQsendQuery not allowed in pipeline mode 1 (1 row) +-- +-- Pipelines and transaction blocks +-- +-- SET LOCAL will issue a warning when modifying a GUC outside of a +-- transaction block. The change will still be valid as a pipeline +-- runs within an implicit transaction block. Sending a sync will +-- commit the implicit transaction block. The first command after a +-- sync will not be seen as belonging to a pipeline. +\startpipeline +SET LOCAL statement_timeout='1h' \bind \g +SHOW statement_timeout \bind \g +\syncpipeline +SHOW statement_timeout \bind \g +SET LOCAL statement_timeout='2h' \bind \g +SHOW statement_timeout \bind \g +\endpipeline +WARNING: SET LOCAL can only be used in transaction blocks + statement_timeout +------------------- + 1h +(1 row) + + statement_timeout +------------------- + 0 +(1 row) + + statement_timeout +------------------- + 2h +(1 row) + +-- REINDEX CONCURRENTLY fails if not the first command in a pipeline. +\startpipeline +SELECT $1 \bind 1 \g +REINDEX TABLE CONCURRENTLY psql_pipeline \bind \g +SELECT $1 \bind 2 \g +\endpipeline + ?column? +---------- + 1 +(1 row) + +ERROR: REINDEX CONCURRENTLY cannot run inside a transaction block +-- REINDEX CONCURRENTLY works if it is the first command in a pipeline. +\startpipeline +REINDEX TABLE CONCURRENTLY psql_pipeline \bind \g +SELECT $1 \bind 2 \g +\endpipeline + ?column? +---------- + 2 +(1 row) + +-- Subtransactions are not allowed in a pipeline. +\startpipeline +SAVEPOINT a \bind \g +SELECT $1 \bind 1 \g +ROLLBACK TO SAVEPOINT a \bind \g +SELECT $1 \bind 2 \g +\endpipeline +ERROR: SAVEPOINT can only be used in transaction blocks +-- LOCK fails as the first command in a pipeline, as not seen in an +-- implicit transaction block. +\startpipeline +LOCK psql_pipeline \bind \g +SELECT $1 \bind 2 \g +\endpipeline +ERROR: LOCK TABLE can only be used in transaction blocks +-- LOCK succeeds as it is not the first command in a pipeline, +-- seen in an implicit transaction block. +\startpipeline +SELECT $1 \bind 1 \g +LOCK psql_pipeline \bind \g +SELECT $1 \bind 2 \g +\endpipeline + ?column? +---------- + 1 +(1 row) + + ?column? +---------- + 2 +(1 row) + +-- VACUUM works as the first command in a pipeline. +\startpipeline +VACUUM psql_pipeline \bind \g +\endpipeline +-- VACUUM fails when not the first command in a pipeline. +\startpipeline +SELECT 1 \bind \g +VACUUM psql_pipeline \bind \g +\endpipeline + ?column? +---------- + 1 +(1 row) + +ERROR: VACUUM cannot run inside a transaction block +-- VACUUM works after a \syncpipeline. +\startpipeline +SELECT 1 \bind \g +\syncpipeline +VACUUM psql_pipeline \bind \g +\endpipeline + ?column? +---------- + 1 +(1 row) + -- Clean up DROP TABLE psql_pipeline; diff --git a/src/test/regress/sql/psql_pipeline.sql b/src/test/regress/sql/psql_pipeline.sql index 38e48054eeb..ec62e6c5f24 100644 --- a/src/test/regress/sql/psql_pipeline.sql +++ b/src/test/regress/sql/psql_pipeline.sql @@ -350,5 +350,77 @@ SELECT 1; SELECT 1; \endpipeline +-- +-- Pipelines and transaction blocks +-- + +-- SET LOCAL will issue a warning when modifying a GUC outside of a +-- transaction block. The change will still be valid as a pipeline +-- runs within an implicit transaction block. Sending a sync will +-- commit the implicit transaction block. The first command after a +-- sync will not be seen as belonging to a pipeline. +\startpipeline +SET LOCAL statement_timeout='1h' \bind \g +SHOW statement_timeout \bind \g +\syncpipeline +SHOW statement_timeout \bind \g +SET LOCAL statement_timeout='2h' \bind \g +SHOW statement_timeout \bind \g +\endpipeline + +-- REINDEX CONCURRENTLY fails if not the first command in a pipeline. +\startpipeline +SELECT $1 \bind 1 \g +REINDEX TABLE CONCURRENTLY psql_pipeline \bind \g +SELECT $1 \bind 2 \g +\endpipeline + +-- REINDEX CONCURRENTLY works if it is the first command in a pipeline. +\startpipeline +REINDEX TABLE CONCURRENTLY psql_pipeline \bind \g +SELECT $1 \bind 2 \g +\endpipeline + +-- Subtransactions are not allowed in a pipeline. +\startpipeline +SAVEPOINT a \bind \g +SELECT $1 \bind 1 \g +ROLLBACK TO SAVEPOINT a \bind \g +SELECT $1 \bind 2 \g +\endpipeline + +-- LOCK fails as the first command in a pipeline, as not seen in an +-- implicit transaction block. +\startpipeline +LOCK psql_pipeline \bind \g +SELECT $1 \bind 2 \g +\endpipeline + +-- LOCK succeeds as it is not the first command in a pipeline, +-- seen in an implicit transaction block. +\startpipeline +SELECT $1 \bind 1 \g +LOCK psql_pipeline \bind \g +SELECT $1 \bind 2 \g +\endpipeline + +-- VACUUM works as the first command in a pipeline. +\startpipeline +VACUUM psql_pipeline \bind \g +\endpipeline + +-- VACUUM fails when not the first command in a pipeline. +\startpipeline +SELECT 1 \bind \g +VACUUM psql_pipeline \bind \g +\endpipeline + +-- VACUUM works after a \syncpipeline. +\startpipeline +SELECT 1 \bind \g +\syncpipeline +VACUUM psql_pipeline \bind \g +\endpipeline + -- Clean up DROP TABLE psql_pipeline; |