Re: Improve explicit cursor handling in pg_stat_statements

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Sami Imseih <samimseih@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-06-05T01:00:42Z
Lists: pgsql-hackers
On Wed, Jun 04, 2025 at 11:51:56AM -0500, Sami Imseih wrote:
>> An enum would shine here IMO, because the value could be
>> self-documented and one would not need to guess what each integer
>> value means.  That could be something like a direction_keyword, filled
>> with FETCH_KEYWORD_LAST, FETCH_KEYWORD_BACKWARD, etc.
> 
> Done in v4.

Mostly good here, some more comments.

+  * If an direction_keyword (i.e., FETCH FORWARD) is used, set this field
+  * to distinguish it from its numeric counterpart (i.e., FETCH 1). This
+  * value is set only within gram.y.

One nitpick comment here is that I would have mentioned that this
matters for query jumbling.

The tests can be in cursors.sql and not utility.sql, which is the test
area for...  Cursors.  :D

FetchDirectionKeywords could be in typedefs.list to avoid the
indentation accident with the structure definition.  There's no actual
practice about that for committers, this note will just serve as a
self-reminder once the v19 branch opens for business when I handle
this patch.
--
Michael

Commits

  1. Show sizes of FETCH queries as constants in pg_stat_statements