Re: Improve explicit cursor handling in pg_stat_statements - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Improve explicit cursor handling in pg_stat_statements
Date
Msg-id aD_K4viAcEY0SrCk@paquier.xyz
Whole thread Raw
In response to Improve explicit cursor handling in pg_stat_statements  (Sami Imseih <samimseih@gmail.com>)
Responses Re: Improve explicit cursor handling in pg_stat_statements
List pgsql-hackers
On Tue, Jun 03, 2025 at 01:04:36PM -0500, Sami Imseih wrote:
> v3 is what I'm thinking: In FetchStmt, introduce a new field called
> explicit_direction (maybe there's a better name?), which is an int that
> we can assign a value to in gram.c. The value will be 0 if no explicit
> direction is used. Otherwise, each of the explicit directions (i.e., FIRST,
> LAST, BACKWARD) will be assigned a unique value. FORWARD ALL and
> BACKWARD ALL will be treated as distinct from FORWARD and BACKWARD.

Hmm.  I was not sure if we'd really need to get down to that, as most
of the grammar keywords have the same parsed meaning, but there's a
good point with LAST for example that uses a negative value for
howMany.  If we silence the number, LAST would map with everything
else that has FETCH_ABSOLUTE.  That would be confusing.

> I considered introducing an enum for these explicit direction values, but
> didn’t find it particularly useful. If you think it would be beneficial,
> I can define an enum in parsenodes.h

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.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: pgsql: postgres_fdw: Inherit the local transaction's access/deferrable
Next
From: Michael Paquier
Date:
Subject: Re: [PATCH] PGSERVICEFILE as part of a normal connection string