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.bonne...@datadoghq.com> Reviewed-by: Jelte Fennema-Nio <postg...@jeltef.nl> Reviewed-by: Kirill Reshke <reshkekir...@gmail.com> Discussion: https://postgr.es/m/cao6_xqroe7jumem1swz55rp9fayx2jwmcp_3m_v51vnofds...@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(-)