From: Álvaro Herrera <alvherre@kurilemu.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix squashing algorithm for query texts
Date: Thu, 12 Jun 2025 12:22:13 +0000
Message-ID: <E1uPgwf-001JiU-1r@gemulon.postgresql.org> (raw)
Fix squashing algorithm for query texts
The algorithm to squash lists of constants added by commit 62d712ecfd94
was a bit too simplistic; we wanted to avoid adding unnecessary
complexity, but cases like direct function calls of typecasting
functions (and others) were missed, and bogus SQL syntax was being shown
in pg_stat_statements normalized query text field. To fix normalization
for those cases, we need the parser to transmit information about were
each list of constant values starts and ends, so add that to a couple of
nodes. Also add a few more test cases to make sure we're doing the
right thing.
The patch initially submitted by Sami added a new private struct in
gram.y to carry the start/end information for A_Expr, but I (Álvaro)
decided that a better fix was to remove the parser indirection via the
in_expr production, and instead create separate components in the a_expr
rule. I'm surprised that this works and doesn't require more changes,
but I assume (without checking) that the grammar used to be more complex
and got simplified at some point.
Bump catversion.
Author: Sami Imseih <samimseih@gmail.com>
Author: Dmitry Dolgov <9erthalion6@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAA5RZ0tRXoPG2y6bMgBCWNDt0Tn=unRerbzYM=oW0syi1=C1OA@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/0f65f3eec478db8ac4f217a608b4478fed023bac
Modified Files
--------------
contrib/pg_stat_statements/expected/select.out | 30 ++
contrib/pg_stat_statements/expected/squashing.out | 535 ++++++++++++++++++----
contrib/pg_stat_statements/pg_stat_statements.c | 83 +---
contrib/pg_stat_statements/sql/select.sql | 8 +
contrib/pg_stat_statements/sql/squashing.sql | 186 ++++++--
src/backend/nodes/gen_node_support.pl | 2 +-
src/backend/nodes/outfuncs.c | 2 +
src/backend/nodes/queryjumblefuncs.c | 153 ++++---
src/backend/nodes/readfuncs.c | 2 +
src/backend/parser/gram.y | 104 ++---
src/backend/parser/parse_expr.c | 4 +
src/include/catalog/catversion.h | 2 +-
src/include/nodes/parsenodes.h | 10 +
src/include/nodes/primnodes.h | 4 +
14 files changed, 833 insertions(+), 292 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: alvherre@kurilemu.de, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Fix squashing algorithm for query texts
In-Reply-To: <E1uPgwf-001JiU-1r@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