diff options
| author | Michael Paquier | 2025-02-25 01:07:24 +0000 |
|---|---|---|
| committer | Michael Paquier | 2025-02-25 01:07:24 +0000 |
| commit | 3ce357584e795762aa6dc45fafc21dccea7e5ec6 (patch) | |
| tree | 97dc2a4cb677b4a9d8d909aaf9794a1c656721a0 /src/test | |
| parent | cbb9086c9ef64b020cb9036f50afc14644bbf734 (diff) | |
psql: Add pipeline status to prompt and some state variables
This commit adds %P to psql prompts, able to report the status of a
pipeline depending on PQpipelineStatus(): on, off or abort.
The following variables are added to report the state of an ongoing
pipeline:
- PIPELINE_SYNC_COUNT: reports the number of piped syncs.
- PIPELINE_COMMAND_COUNT: reports the number of piped commands, a
command being either \bind, \bind_named, \close or \parse.
- PIPELINE_RESULT_COUNT: reports the results available to read with
\getresults.
These variables can be used with \echo or in a prompt, using "%:name:"
in PROMPT1, PROMPT2 or PROMPT3. Some basic regression tests are added
for these. The suggestion to use variables to show the details about
the status counters comes from me. The original patch proposed was less
extensible, hardcoding the output in the prompt.
Author: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Discussion: https://postgr.es/m/CAO6_XqroE7JuMEm1sWz55rp9fAYX2JwmcP_3m_v51vnOFdsLiQ@mail.gmail.com
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/psql_pipeline.out | 22 | ||||
| -rw-r--r-- | src/test/regress/sql/psql_pipeline.sql | 11 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/test/regress/expected/psql_pipeline.out b/src/test/regress/expected/psql_pipeline.out index f4603d2b66a..3df2415a840 100644 --- a/src/test/regress/expected/psql_pipeline.out +++ b/src/test/regress/expected/psql_pipeline.out @@ -57,12 +57,24 @@ SELECT $1, $2 \bind 'val2' 'val3' \g -- Send multiple syncs \startpipeline +\echo :PIPELINE_COMMAND_COUNT +0 +\echo :PIPELINE_SYNC_COUNT +0 +\echo :PIPELINE_RESULT_COUNT +0 SELECT $1 \bind 'val1' \g \syncpipeline \syncpipeline SELECT $1, $2 \bind 'val2' 'val3' \g \syncpipeline SELECT $1, $2 \bind 'val4' 'val5' \g +\echo :PIPELINE_COMMAND_COUNT +1 +\echo :PIPELINE_SYNC_COUNT +3 +\echo :PIPELINE_RESULT_COUNT +2 \endpipeline ?column? ---------- @@ -303,13 +315,21 @@ SELECT $1 \bind 2 \g SELECT $1 \bind 1 \g SELECT $1 \bind 2 \g SELECT $1 \bind 3 \g +\echo :PIPELINE_SYNC_COUNT +0 \syncpipeline +\echo :PIPELINE_SYNC_COUNT +1 +\echo :PIPELINE_RESULT_COUNT +3 \getresults 1 ?column? ---------- 1 (1 row) +\echo :PIPELINE_RESULT_COUNT +2 SELECT $1 \bind 4 \g \getresults 3 ?column? @@ -322,6 +342,8 @@ SELECT $1 \bind 4 \g 3 (1 row) +\echo :PIPELINE_RESULT_COUNT +0 \endpipeline ?column? ---------- diff --git a/src/test/regress/sql/psql_pipeline.sql b/src/test/regress/sql/psql_pipeline.sql index ec62e6c5f24..6517ebb71f8 100644 --- a/src/test/regress/sql/psql_pipeline.sql +++ b/src/test/regress/sql/psql_pipeline.sql @@ -27,12 +27,18 @@ SELECT $1, $2 \bind 'val2' 'val3' \g -- Send multiple syncs \startpipeline +\echo :PIPELINE_COMMAND_COUNT +\echo :PIPELINE_SYNC_COUNT +\echo :PIPELINE_RESULT_COUNT SELECT $1 \bind 'val1' \g \syncpipeline \syncpipeline SELECT $1, $2 \bind 'val2' 'val3' \g \syncpipeline SELECT $1, $2 \bind 'val4' 'val5' \g +\echo :PIPELINE_COMMAND_COUNT +\echo :PIPELINE_SYNC_COUNT +\echo :PIPELINE_RESULT_COUNT \endpipeline -- \startpipeline should not have any effect if already in a pipeline. @@ -174,10 +180,15 @@ SELECT $1 \bind 2 \g SELECT $1 \bind 1 \g SELECT $1 \bind 2 \g SELECT $1 \bind 3 \g +\echo :PIPELINE_SYNC_COUNT \syncpipeline +\echo :PIPELINE_SYNC_COUNT +\echo :PIPELINE_RESULT_COUNT \getresults 1 +\echo :PIPELINE_RESULT_COUNT SELECT $1 \bind 4 \g \getresults 3 +\echo :PIPELINE_RESULT_COUNT \endpipeline -- \syncpipeline count as one command to fetch for \getresults. |
