Subject: Re: psql's FETCH_COUNT (cursor) is not being respected for CTEs

From: Laurenz Albe <[email-masked]>
Date: Fri, 29 Mar 2024 14:07:06 +0100

On Tue, 2024-01-30 at 15:29 +0100, Daniel Verite wrote:
> PFA a rebased version.

I had a look at patch 0001 (0002 will follow).

> - <sect1 id="libpq-single-row-mode">
> -  <title>Retrieving Query Results Row-by-Row</title>
> + <sect1 id="libpq-chunked-results-modes">
> +  <title>Retrieving Query Results by chunks</title>

That should be "in chunks".

> +    <para>
> +   <variablelist>
> +    <varlistentry id="libpq-PQsetChunkedRowsMode">
> +      <term><function>PQsetChunkedRowsMode</function>
> +        <indexterm><primary>PQsetChunkedRowsMode</primary></indexterm></term>
> +     <listitem>
> +      <para>
> +       Select the mode retrieving results in chunks for the currently-executing query.

That is questionable English.  How about

  Select to receive the results for the currently-executing query in chunks.

> +       This function is similar to <xref linkend="libpq-PQsetSingleRowMode"/>,
> +       except that it can retrieve a user-specified number of rows
> +       per call to <xref linkend="libpq-PQgetResult"/>, instead of a single row.

The "user-specified number" is "maxRows".  So a better wording would be:

  ... except that it can retrieve <replaceable>maxRows</replaceable> rows
  per call to <xref linkend="libpq-PQgetResult"/> instead of a single row.

> -    error.  But in single-row mode, those rows will have already been
> +    error.  But in single-row or chunked modes, those rows will have already been

I'd say it should be "in *the* single-row or chunk modes".

> --- a/src/interfaces/libpq/fe-exec.c
> +++ b/src/interfaces/libpq/fe-exec.c
> @@ -41,7 +41,8 @@ char     *const pgresStatus[] = {
>     "PGRES_COPY_BOTH",
>     "PGRES_SINGLE_TUPLE",
>     "PGRES_PIPELINE_SYNC",
> -   "PGRES_PIPELINE_ABORTED"
> +   "PGRES_PIPELINE_ABORTED",
> +   "PGRES_TUPLES_CHUNK"
>  };

I think that PGRES_SINGLE_TUPLE and PGRES_TUPLES_CHUNK should be next to each
other, but that's no big thing.
The same applies to the change in src/interfaces/libpq/libpq-fe.h

I understand that we need to keep the single-row mode for compatibility
reasons.  But I think that under the hood, "single-row mode" should be the
same as "chunk mode with chunk size one".
That should save some code repetition.

Yours,
Laurenz Albe