Support retrieval of results in chunks with libpq.
Tom Lane <tgl@sss.pgh.pa.us>
Support retrieval of results in chunks with libpq. This patch generalizes libpq's existing single-row mode to allow individual partial-result PGresults to contain up to N rows, rather than always one row. This reduces malloc overhead compared to plain single-row mode, and it is very useful for psql's FETCH_COUNT feature, since otherwise we'd have to add code (and cycles) to either merge single-row PGresults into a bigger one or teach psql's results-printing logic to accept arrays of PGresults. To avoid API breakage, PQsetSingleRowMode() remains the same, and we add a new function PQsetChunkedRowsMode() to invoke the more general case. Also, PGresults obtained the old way continue to carry the PGRES_SINGLE_TUPLE status code, while if PQsetChunkedRowsMode() is used then their status code is PGRES_TUPLES_CHUNK. The underlying logic is the same either way, though. Daniel Vérité, reviewed by Laurenz Albe and myself (and whacked around a bit by me, so any remaining bugs are my fault) Discussion: https://postgr.es/m/CAKZiRmxsVTkO928CM+-ADvsMyePmU3L9DQCa9NwqjvLPcEe5QA@mail.gmail.com
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/libpq.sgml | modified | +80 −27 |
| src/backend/replication/libpqwalreceiver/libpqwalreceiver.c | modified | +2 −1 |
| src/bin/pg_amcheck/pg_amcheck.c | modified | +1 −0 |
| src/interfaces/libpq/exports.txt | modified | +1 −0 |
| src/interfaces/libpq/fe-exec.c | modified | +93 −53 |
| src/interfaces/libpq/fe-protocol3.c | modified | +2 −1 |
| src/interfaces/libpq/libpq-fe.h | modified | +3 −1 |
| src/interfaces/libpq/libpq-int.h | modified | +7 −3 |
| src/test/modules/libpq_pipeline/libpq_pipeline.c | modified | +40 −0 |
| src/test/modules/libpq_pipeline/traces/singlerow.trace | modified | +14 −0 |
Documentation touched
Discussion
- psql's FETCH_COUNT (cursor) is not being respected for CTEs 31 messages · 2023-01-04 → 2024-04-08