Remove the query_id_squash_values GUC
authorÁlvaro Herrera <[email protected]>
Thu, 27 Mar 2025 12:33:37 +0000 (13:33 +0100)
committerÁlvaro Herrera <[email protected]>
Thu, 27 Mar 2025 12:33:37 +0000 (13:33 +0100)
Commit 62d712ecfd94 introduced the capability to calculate the same
queryId for queries with different lengths of constants in a list for an
IN clause.  This behavior was originally enabled with a GUC
query_id_squash_values.  After a discussion about the value of such a
GUC, it was decided to back out of the use of a GUC and make the
squashing behavior the only available option.

Author: Sami Imseih <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/CA+q6zcVTK-3C-8NWV1oY2NZrvtnMCDqnyYYyk1T7WMUG65MeOQ@mail.gmail.com

contrib/pg_stat_statements/expected/dml.out
contrib/pg_stat_statements/expected/squashing.out
contrib/pg_stat_statements/sql/squashing.sql
doc/src/sgml/config.sgml
doc/src/sgml/pgstatstatements.sgml
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/queryjumble.h

index acc2c5e5241c8704d665c955b08baaf72aca1dbb..347cb8699e432029f1cf00135a894e71c2e679ac 100644 (file)
@@ -80,7 +80,7 @@ SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
      1 |   10 | INSERT INTO pgss_dml_tab VALUES(generate_series($1, $2), $3)
      1 |   12 | SELECT * FROM pgss_dml_tab ORDER BY a
      2 |    4 | SELECT * FROM pgss_dml_tab WHERE a > $1 ORDER BY a
-     1 |    8 | SELECT * FROM pgss_dml_tab WHERE a IN ($1, $2, $3, $4, $5)
+     1 |    8 | SELECT * FROM pgss_dml_tab WHERE a IN ($1 /*, ... */)
      1 |    1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t
      1 |    0 | SET pg_stat_statements.track_utility = $1
      6 |    6 | UPDATE pgss_dml_tab SET b = $1 WHERE a = $2
index 55aa51094336eb6056eb51e717a2cac19a797c14..7b138af098c9f9e768d20eaca47aa8d39e6759d3 100644 (file)
@@ -4,39 +4,7 @@
 CREATE EXTENSION pg_stat_statements;
 CREATE TABLE test_squash (id int, data int);
 -- IN queries
--- No squashing is performed, as a baseline result
-SELECT pg_stat_statements_reset() IS NOT NULL AS t;
- t 
----
- t
-(1 row)
-
-SELECT * FROM test_squash WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9);
- id | data 
-----+------
-(0 rows)
-
-SELECT * FROM test_squash WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
- id | data 
-----+------
-(0 rows)
-
-SELECT * FROM test_squash WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
- id | data 
-----+------
-(0 rows)
-
-SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C";
-                                        query                                         | calls 
---------------------------------------------------------------------------------------+-------
- SELECT * FROM test_squash WHERE id IN ($1, $2, $3, $4, $5, $6, $7, $8, $9)           |     1
- SELECT * FROM test_squash WHERE id IN ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)      |     1
- SELECT * FROM test_squash WHERE id IN ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) |     1
- SELECT pg_stat_statements_reset() IS NOT NULL AS t                                   |     1
-(4 rows)
-
 -- Normal scenario, too many simple constants for an IN query
-SET query_id_squash_values = on;
 SELECT pg_stat_statements_reset() IS NOT NULL AS t;
  t 
 ---
@@ -461,4 +429,3 @@ SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C";
  SELECT pg_stat_statements_reset() IS NOT NULL AS t |     1
 (2 rows)
 
-RESET query_id_squash_values;
index 56ee8ccb9a1aebcb612b06cf2e0969d65bbda3ae..908be81ff2b7dc486f506c3ce5c2bd1f542c9abc 100644 (file)
@@ -7,16 +7,7 @@ CREATE TABLE test_squash (id int, data int);
 
 -- IN queries
 
--- No squashing is performed, as a baseline result
-SELECT pg_stat_statements_reset() IS NOT NULL AS t;
-SELECT * FROM test_squash WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9);
-SELECT * FROM test_squash WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
-SELECT * FROM test_squash WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
-SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C";
-
 -- Normal scenario, too many simple constants for an IN query
-SET query_id_squash_values = on;
-
 SELECT pg_stat_statements_reset() IS NOT NULL AS t;
 SELECT * FROM test_squash WHERE id IN (1);
 SELECT * FROM test_squash WHERE id IN (1, 2, 3);
@@ -177,4 +168,3 @@ SELECT pg_stat_statements_reset() IS NOT NULL AS t;
 SELECT ARRAY[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
 SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C";
 
-RESET query_id_squash_values;
index f86135fbe1d64d04835459493b0bd91d62392446..65ab95be37071bcb076b6d493483ea50279826f9 100644 (file)
@@ -8726,36 +8726,6 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
       </listitem>
      </varlistentry>
 
-     <varlistentry id="guc-query-id-squash-values" xreflabel="query_id_squash_values">
-      <term><varname>query_id_squash_values</varname> (<type>bool</type>)
-      <indexterm>
-       <primary><varname>query_id_squash_values</varname> configuration parameter</primary>
-      </indexterm>
-      </term>
-      <listitem>
-       <para>
-        Specifies how a list of constants (e.g., for an <literal>IN</literal>
-        clause) contributes to the query identifier computation.
-        Normally, every element of such a list contributes to the query
-        identifier separately, which means that two queries that only differ
-        in the number of elements in such a list would get different query
-        identifiers.
-        If this parameter is on, a list of constants will not contribute
-        to the query identifier. This means that two queries whose only
-        difference is the number of constants in such a list are going to get the
-        same query identifier.
-       </para>
-       <para>
-        Only constants are affected; bind parameters do not benefit from this
-        functionality. The default value is <literal>off</literal>.
-       </para>
-       <para>
-        This parameter also affects how <xref linkend="pgstatstatements"/>
-        generates normalized query texts.
-       </para>
-      </listitem>
-     </varlistentry>
-
      <varlistentry id="guc-log-statement-stats">
       <term><varname>log_statement_stats</varname> (<type>boolean</type>)
       <indexterm>
index 625b84ebfefd12cd5604a70c3cd2b7d8a041de4d..7baa07dcdbf7f56ded064365062f8bcf3d88024f 100644 (file)
    In some cases, queries with visibly different texts might get merged into a
    single <structname>pg_stat_statements</structname> entry; as explained above,
    this is expected to happen for semantically equivalent queries.
-   In addition, if <varname>query_id_squash_values</varname> is enabled
-   and the only difference between queries is the number of elements in a list
-   of constants, the list will get squashed down to a single element but shown
+   In addition, if the only difference between queries is the number of elements
+   in a list of constants, the list will get squashed down to a single element but shown
    with a commented-out list indicator:
 
 <screen>
-=# SET query_id_squash_values = on;
 =# SELECT pg_stat_statements_reset();
 =# SELECT * FROM test WHERE a IN (1, 2, 3, 4, 5, 6, 7);
 =# SELECT * FROM test WHERE a IN (1, 2, 3, 4, 5, 6, 7, 8);
index 1d9abd890288aa0fb472cebcb1fb157754346278..513cf92d357f319186cbf56d912f603d54e51d56 100644 (file)
@@ -46,9 +46,6 @@
 /* GUC parameters */
 int            compute_query_id = COMPUTE_QUERY_ID_AUTO;
 
-/* Whether to merge constants in a list when computing query_id */
-bool       query_id_squash_values = false;
-
 /*
  * True when compute_query_id is ON or AUTO, and a module requests them.
  *
@@ -472,7 +469,7 @@ IsSquashableConstList(List *elements, Node **firstExpr, Node **lastExpr)
     * If squashing is disabled, or the list is too short, we don't try to
     * squash it.
     */
-   if (!query_id_squash_values || list_length(elements) < 2)
+   if (list_length(elements) < 2)
        return false;
 
    foreach(temp, elements)
@@ -520,13 +517,10 @@ do { \
 #include "queryjumblefuncs.funcs.c"
 
 /*
- * When query_id_squash_values is enabled, we jumble lists of constant
- * elements as one individual item regardless of how many elements are
- * in the list.  This means different queries jumble to the same query_id,
- * if the only difference is the number of elements in the list.
- *
- * If query_id_squash_values is disabled or the list is not "simple
- * enough", we jumble each element normally.
+ * We jumble lists of constant elements as one individual item regardless
+ * of how many elements are in the list.  This means different queries
+ * jumble to the same query_id, if the only difference is the number of
+ * elements in the list.
  */
 static void
 _jumbleElements(JumbleState *jstate, List *elements)
index 9e6c900d14679f6b82622f338f32621600740455..bf6b55ee8304877d90aa8707fc82b10c4b1e6642 100644 (file)
@@ -116,7 +116,6 @@ typedef struct
    bool        redirection_done;
    bool        IsBinaryUpgrade;
    bool        query_id_enabled;
-   bool        query_id_squash_values;
    int         max_safe_fds;
    int         MaxBackends;
    int         num_pmchild_slots;
@@ -778,7 +777,6 @@ save_backend_variables(BackendParameters *param,
    param->redirection_done = redirection_done;
    param->IsBinaryUpgrade = IsBinaryUpgrade;
    param->query_id_enabled = query_id_enabled;
-   param->query_id_squash_values = query_id_squash_values;
    param->max_safe_fds = max_safe_fds;
 
    param->MaxBackends = MaxBackends;
@@ -1039,7 +1037,6 @@ restore_backend_variables(BackendParameters *param)
    redirection_done = param->redirection_done;
    IsBinaryUpgrade = param->IsBinaryUpgrade;
    query_id_enabled = param->query_id_enabled;
-   query_id_squash_values = param->query_id_squash_values;
    max_safe_fds = param->max_safe_fds;
 
    MaxBackends = param->MaxBackends;
index 989825d3a9c82e76d5f70b5b5937eb952bd9c270..76c7c6bb4b17141189da730e9eb7828799c4de27 100644 (file)
@@ -2122,16 +2122,6 @@ struct config_bool ConfigureNamesBool[] =
        NULL, NULL, NULL
    },
 
-   {
-       {"query_id_squash_values", PGC_USERSET, STATS_MONITORING,
-           gettext_noop("Allows to merge constants in a list when computing "
-                        "query_id."),
-       },
-       &query_id_squash_values,
-       false,
-       NULL, NULL, NULL
-   },
-
    {
        {"vacuum_truncate", PGC_USERSET, VACUUM_DEFAULT,
            gettext_noop("Enables vacuum to truncate empty pages at the end of the table."),
index 2246ccb85a703162c03c4f18cb3bb283600bb5d3..7c12434efa2f15a3f2b9d21fbe524dc900c3cba0 100644 (file)
 # - Monitoring -
 
 #compute_query_id = auto
-#query_id_squash_values = off
 #log_statement_stats = off
 #log_parser_stats = off
 #log_planner_stats = off
index 62794c5a901ba0ea25d3e2b74dfc88e7387e814d..da7c7abed2e6adaf191d0a306539aeda9c2deb22 100644 (file)
@@ -86,7 +86,6 @@ extern JumbleState *JumbleQuery(Query *query);
 extern void EnableQueryId(void);
 
 extern PGDLLIMPORT bool query_id_enabled;
-extern PGDLLIMPORT bool query_id_squash_values;
 
 /*
  * Returns whether query identifier computation has been enabled, either