Re: Improve explicit cursor handling in pg_stat_statements

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Sami Imseih <samimseih(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Improve explicit cursor handling in pg_stat_statements
Date: 2025-06-04 04:26:10
Message-ID: aD_K4viAcEY0SrCk@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

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