From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Show sizes of FETCH queries as constants in pg_stat_statements
Date: Tue, 01 Jul 2025 23:40:15 +0000
Message-ID: <E1uWkaF-004GSC-0p@gemulon.postgresql.org> (raw)
Show sizes of FETCH queries as constants in pg_stat_statements
Prior to this patch, every FETCH call would generate a unique queryId
with a different size specified. Depending on the workloads, this could
lead to a significant bloat in pg_stat_statements, as repeatedly calling
a specific cursor would result in a new queryId each time. For example,
FETCH 1 c1; and FETCH 2 c1; would produce different queryIds.
This patch improves the situation by normalizing the fetch size, so as
semantically similar statements generate the same queryId. As a result,
statements like the below, which differ syntactically but have the same
effect, will now share a single queryId:
FETCH FROM c1
FETCH NEXT c1
FETCH 1 c1
In order to do a normalization based on the keyword used in FETCH,
FetchStmt is tweaked with a new FetchDirectionKeywords. This matters
for "howMany", which could be set to a negative value depending on the
direction, and we want to normalize the queries with enough information
about the direction keywords provided, including RELATIVE, ABSOLUTE or
all the ALL variants.
Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0tA6LbHCg2qSS+KuM850BZC_+ZgHV7Ug6BXw22TNyF+MA@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/bee23ea4ddc46198c95a4e73a83f453c09e04bf8
Modified Files
--------------
contrib/pg_stat_statements/expected/cursors.out | 141 ++++++++++++++++++++-
.../pg_stat_statements/expected/level_tracking.out | 4 +-
contrib/pg_stat_statements/expected/utility.out | 2 +-
contrib/pg_stat_statements/sql/cursors.sql | 43 +++++++
src/backend/parser/gram.y | 50 ++++++--
src/include/nodes/parsenodes.h | 35 ++++-
src/tools/pgindent/typedefs.list | 1 +
7 files changed, 259 insertions(+), 17 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Show sizes of FETCH queries as constants in pg_stat_statements
In-Reply-To: <E1uWkaF-004GSC-0p@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox