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

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: "Daniel Verite" <daniel@manitou-mail.org>
Cc: "PostgreSQL Hackers" <pgsql-hackers@postgresql.org>, Robert Haas <robertmhaas@gmail.com>, Jakub Wartak <jakub.wartak@enterprisedb.com>
Date: 2023-03-24T20:12:58Z
Lists: pgsql-hackers
"Daniel Verite" <daniel@manitou-mail.org> writes:
> PFA an updated patch.

This gives me several "-Wincompatible-pointer-types" warnings
(as are also reported by the cfbot):

common.c: In function 'ExecQueryAndProcessResults':
common.c:1686:24: warning: passing argument 1 of 'PrintQueryTuples' from incompatible pointer type [-Wincompatible-pointer-types]
       PrintQueryTuples(result_array, ntuples, &my_popt, tuples_fout);
                        ^~~~~~~~~~~~
common.c:679:35: note: expected 'const PGresult **' {aka 'const struct pg_result **'} but argument is of type 'PGresult **' {aka 'struct pg_result **'}
 PrintQueryTuples(const PGresult **result, int nresults, const printQueryOpt *opt,
                  ~~~~~~~~~~~~~~~~~^~~~~~
common.c:1720:24: warning: passing argument 1 of 'PrintQueryTuples' from incompatible pointer type [-Wincompatible-pointer-types]
       PrintQueryTuples(result_array, ntuples, &my_popt, tuples_fout);
                        ^~~~~~~~~~~~
common.c:679:35: note: expected 'const PGresult **' {aka 'const struct pg_result **'} but argument is of type 'PGresult **' {aka 'struct pg_result **'}
 PrintQueryTuples(const PGresult **result, int nresults, const printQueryOpt *opt,
                  ~~~~~~~~~~~~~~~~~^~~~~~

I think the cause is the inconsistency about whether PGresult pointers
are pointer-to-const or not.  Even without compiler warnings, I find
code like this very ugly:

-				success = PrintQueryTuples(result, opt, printQueryFout);
+				success = PrintQueryTuples((const PGresult**)&result, 1, opt, printQueryFout);

I think what you probably ought to do to avoid all that is to change
the arguments of PrintQueryResult and nearby routines to be "const
PGresult *result" not just "PGresult *result".

I find it sad that we can't get rid of ExecQueryUsingCursor().
Maybe a little effort towards reducing overhead in the single-row
mode would help?

			regards, tom lane



Commits

  1. Further review for re-implementation of psql's FETCH_COUNT feature.

  2. Re-implement psql's FETCH_COUNT feature atop libpq's chunked mode.

  3. Support retrieval of results in chunks with libpq.

  4. Attempt to fix newly added Memoize regression test