From b3dca7e2eaf3b74fceb4493f322b90c2321139f2 Mon Sep 17 00:00:00 2001 From: Ilya Staroverov Date: Mon, 26 Oct 2026 13:03:01 +0300 Subject: [PATCH v1 07/11] Include VARIADIC in query jumbling FuncExpr.funcvariadic and Aggref.aggvariadic, added in 9.3 and 9.4, have never been part of the query ID. For a function taking VARIADIC "any", like format() or concat(), they tell whether the last argument is an array of the variadic arguments or one of them. So queries like SELECT format('%s', VARIADIC ARRAY['a', 'b']), which returns "a", and the same without VARIADIC, which returns "{a,b}", were merged into a single pg_stat_statements entry. For other variadic functions, the parser combines the variadic arguments into an array and sets these fields with or without VARIADIC, so such calls are still merged. Include both fields in query jumbling. The built-in aggregates taking VARIADIC "any" are ordered-set aggregates, which can't be called with VARIADIC, so the tests only cover functions. This changes the query IDs of the queries with function calls or aggregates, so it is for master only. Author: Ilya Staroverov --- contrib/pg_stat_statements/expected/select.out | 8 +++++--- src/include/nodes/primnodes.h | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/contrib/pg_stat_statements/expected/select.out b/contrib/pg_stat_statements/expected/select.out index 66a1524417..9536a2f306 100644 --- a/contrib/pg_stat_statements/expected/select.out +++ b/contrib/pg_stat_statements/expected/select.out @@ -1217,11 +1217,13 @@ SELECT calls, query FROM pg_stat_statements ORDER BY query COLLATE "C"; calls | query -------+------------------------------------------------------------------------ 0 | SELECT calls, query FROM pg_stat_statements ORDER BY query COLLATE "C" - 2 | SELECT concat(VARIADIC ARRAY[$1 /*, ... */]) - 2 | SELECT format($1, VARIADIC ARRAY[$2 /*, ... */]) + 1 | SELECT concat(ARRAY[$1 /*, ... */]) + 1 | SELECT concat(VARIADIC ARRAY[$1 /*, ... */]) + 1 | SELECT format($1, ARRAY[$2 /*, ... */]) + 1 | SELECT format($1, VARIADIC ARRAY[$2 /*, ... */]) 2 | SELECT jsonb_extract_path($1, a::text, b::text) FROM pgss_empty_tab 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t -(5 rows) +(7 rows) SELECT pg_stat_statements_reset() IS NOT NULL AS t; t diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index a448f88861..327359e7f7 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.h @@ -508,7 +508,7 @@ typedef struct Aggref * true if variadic arguments have been combined into an array last * argument */ - bool aggvariadic pg_node_attr(query_jumble_ignore); + bool aggvariadic; /* aggregate kind (see pg_aggregate.h) */ char aggkind pg_node_attr(query_jumble_ignore); @@ -785,7 +785,7 @@ typedef struct FuncExpr * true if variadic arguments have been combined into an array last * argument */ - bool funcvariadic pg_node_attr(query_jumble_ignore); + bool funcvariadic; /* how to display this function call */ CoercionForm funcformat pg_node_attr(query_jumble_ignore); /* OID of collation of result */ -- 2.43.0