mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
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
This commit is contained in:
@@ -434,7 +434,10 @@ struct pg_conn
|
||||
bool nonblocking; /* whether this connection is using nonblock
|
||||
* sending semantics */
|
||||
PGpipelineStatus pipelineStatus; /* status of pipeline mode */
|
||||
bool partialResMode; /* true if single-row or chunked mode */
|
||||
bool singleRowMode; /* return current query result row-by-row? */
|
||||
int maxChunkSize; /* return query result in chunks not exceeding
|
||||
* this number of rows */
|
||||
char copy_is_binary; /* 1 = copy binary, 0 = copy text */
|
||||
int copy_already_done; /* # bytes already returned in COPY OUT */
|
||||
PGnotify *notifyHead; /* oldest unreported Notify msg */
|
||||
@@ -535,12 +538,13 @@ struct pg_conn
|
||||
* and error_result is true, then we need to return a PGRES_FATAL_ERROR
|
||||
* result, but haven't yet constructed it; text for the error has been
|
||||
* appended to conn->errorMessage. (Delaying construction simplifies
|
||||
* dealing with out-of-memory cases.) If next_result isn't NULL, it is a
|
||||
* PGresult that will replace "result" after we return that one.
|
||||
* dealing with out-of-memory cases.) If saved_result isn't NULL, it is a
|
||||
* PGresult that will replace "result" after we return that one; we use
|
||||
* that in partial-result mode to remember the query's tuple metadata.
|
||||
*/
|
||||
PGresult *result; /* result being constructed */
|
||||
bool error_result; /* do we need to make an ERROR result? */
|
||||
PGresult *next_result; /* next result (used in single-row mode) */
|
||||
PGresult *saved_result; /* original, empty result in partialResMode */
|
||||
|
||||
/* Assorted state for SASL, SSL, GSS, etc */
|
||||
const pg_fe_sasl_mech *sasl;
|
||||
|
||||
Reference in New Issue
Block a user