Introduce squashing of constant lists in query jumbling
authorÁlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 18 Mar 2025 17:56:11 +0000 (18:56 +0100)
committerÁlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 18 Mar 2025 17:56:11 +0000 (18:56 +0100)
commit62d712ecfd940f60e68bde5b6972b6859937c412
treecad7cd2202f4dd3ad75c152e6aca98246ef661cd
parent247ce06b883d7b3a40d08312dc03dfb37fbff212
Introduce squashing of constant lists in query jumbling

pg_stat_statements produces multiple entries for queries like
    SELECT something FROM table WHERE col IN (1, 2, 3, ...)

depending on the number of parameters, because every element of
ArrayExpr is individually jumbled.  Most of the time that's undesirable,
especially if the list becomes too large.

Fix this by introducing a new GUC query_id_squash_values which modifies
the node jumbling code to only consider the first and last element of a
list of constants, rather than each list element individually.  This
affects both the query_id generated by query jumbling, as well as
pg_stat_statements query normalization so that it suppresses printing of
the individual elements of such a list.

The default value is off, meaning the previous behavior is maintained.

Author: Dmitry Dolgov <9erthalion6@gmail.com>
Reviewed-by: Sergey Dudoladov (mysterious, off-list)
Reviewed-by: David Geier <geidav.pg@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Sutou Kouhei <kou@clear-code.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Marcos Pegoraro <marcos@f10.com.br>
Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>
Reviewed-by: Zhihong Yu <zyu@yugabyte.com>
Tested-by: Yasuo Honda <yasuo.honda@gmail.com>
Tested-by: Sergei Kornilov <sk@zsrv.org>
Tested-by: Maciek Sakrejda <m.sakrejda@gmail.com>
Tested-by: Chengxi Sun <sunchengxi@highgo.com>
Tested-by: Jakub Wartak <jakub.wartak@enterprisedb.com>
Discussion: https://postgr.es/m/CA+q6zcWtUbT_Sxj0V6HY6EZ89uv5wuG5aefpe_9n0Jr3VwntFg@mail.gmail.com
15 files changed:
contrib/pg_stat_statements/Makefile
contrib/pg_stat_statements/expected/squashing.out [new file with mode: 0644]
contrib/pg_stat_statements/meson.build
contrib/pg_stat_statements/pg_stat_statements.c
contrib/pg_stat_statements/sql/squashing.sql [new file with mode: 0644]
doc/src/sgml/config.sgml
doc/src/sgml/pgstatstatements.sgml
src/backend/nodes/gen_node_support.pl
src/backend/nodes/queryjumblefuncs.c
src/backend/postmaster/launch_backend.c
src/backend/utils/misc/guc_tables.c
src/backend/utils/misc/postgresql.conf.sample
src/include/nodes/nodes.h
src/include/nodes/primnodes.h
src/include/nodes/queryjumble.h