]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix squashing algorithm for query texts
authorÁlvaro Herrera <alvherre@kurilemu.de>
Thu, 12 Jun 2025 12:21:21 +0000 (14:21 +0200)
committerÁlvaro Herrera <alvherre@kurilemu.de>
Thu, 12 Jun 2025 12:21:21 +0000 (14:21 +0200)
commit0f65f3eec478db8ac4f217a608b4478fed023bac
treeb792a68d36cd2e559c3e579214833a9348ab16f9
parentf7b11414e939a00faa63e27feae69ceef5bf4b02
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
14 files changed:
contrib/pg_stat_statements/expected/select.out
contrib/pg_stat_statements/expected/squashing.out
contrib/pg_stat_statements/pg_stat_statements.c
contrib/pg_stat_statements/sql/select.sql
contrib/pg_stat_statements/sql/squashing.sql
src/backend/nodes/gen_node_support.pl
src/backend/nodes/outfuncs.c
src/backend/nodes/queryjumblefuncs.c
src/backend/nodes/readfuncs.c
src/backend/parser/gram.y
src/backend/parser/parse_expr.c
src/include/catalog/catversion.h
src/include/nodes/parsenodes.h
src/include/nodes/primnodes.h