pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: psql: Add support for pipelines
Date: Fri, 21 Feb 2025 02:20:19 +0000
Message-ID: <E1tlIeK-000Opa-32@gemulon.postgresql.org> (raw)

psql: Add support for pipelines

With \bind, \parse, \bind_named and \close, it is possible to issue
queries from psql using the extended protocol.  However, it was not
possible to send these queries using libpq's pipeline mode.  This
feature has two advantages:
- Testing.  Pipeline tests were only possible with pgbench, using TAP
tests.  It now becomes possible to have more SQL tests that are able to
stress the backend with pipelines and extended queries.  More tests will
be added in a follow-up commit that were discussed on some other
threads.  Some external projects in the community had to implement their
own facility to work around this limitation.
- Emulation of custom workloads, with more control over the actions
taken by a client with libpq APIs.  It is possible to emulate more
workload patterns to bottleneck the backend with the extended query
protocol.

This patch adds six new meta-commands to be able to control pipelines:
* \startpipeline starts a new pipeline.  All extended queries are queued
until the end of the pipeline are reached or a sync request is sent and
processed.
* \endpipeline ends an existing pipeline.  All queued commands are sent
to the server and all responses are processed by psql.
* \syncpipeline queues a synchronisation request, without flushing the
commands to the server, equivalent of PQsendPipelineSync().
* \flush, equivalent of PQflush().
* \flushrequest, equivalent of PQsendFlushRequest()
* \getresults reads the server's results for the queries in a pipeline.
Unsent data is automatically pushed when \getresults is called.  It is
possible to control the number of results read in a single meta-command
execution with an optional parameter, 0 means that all the results
should be read.

Author: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Discussion: https://postgr.es/m/CAO6_XqroE7JuMEm1sWz55rp9fAYX2JwmcP_3m_v51vnOFdsLiQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/41625ab8ea3d0a2656dd0f067f1f0b61df63af97

Modified Files
--------------
doc/src/sgml/ref/psql-ref.sgml              |  67 ++++
src/bin/psql/command.c                      | 170 ++++++++
src/bin/psql/common.c                       | 288 +++++++++++++-
src/bin/psql/help.c                         |   7 +
src/bin/psql/settings.h                     |  12 +
src/bin/psql/tab-complete.in.c              |   8 +-
src/test/regress/expected/psql.out          |   6 +
src/test/regress/expected/psql_pipeline.out | 589 ++++++++++++++++++++++++++++
src/test/regress/parallel_schedule          |   2 +-
src/test/regress/sql/psql.sql               |   6 +
src/test/regress/sql/psql_pipeline.sql      | 354 +++++++++++++++++
11 files changed, 1497 insertions(+), 12 deletions(-)



Message-ID: <E1tlIeK-000Opa-32@gemulon.postgresql.org>
Permalink:  ../E1tlIeK-000Opa-32@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tlIeK-000Opa-32@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: psql: Add support for pipelines
  In-Reply-To: <E1tlIeK-000Opa-32@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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