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
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
---
SELECT pg_stat_statements_reset() IS NOT NULL AS t | 1
(2 rows)
-RESET query_id_squash_values;
-- 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);
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;
</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>
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);
/* 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.
*
* 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)
#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)
bool redirection_done;
bool IsBinaryUpgrade;
bool query_id_enabled;
- bool query_id_squash_values;
int max_safe_fds;
int MaxBackends;
int num_pmchild_slots;
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;
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;
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."),
# - Monitoring -
#compute_query_id = auto
-#query_id_squash_values = off
#log_statement_stats = off
#log_parser_stats = off
#log_planner_stats = off
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