JumbleQuery ma treat different GROUP BY expr as the same

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: JumbleQuery ma treat different GROUP BY expr as the same
Date: 2026-01-10 13:13:39
Message-ID: CACJufxEy2W+tCqC7XuJ94r3ivWsM=onKJp94kRFx3hoARjBeFQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

drop table if exists t;
create table t(a text, b text, c int);
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
explain(costs off, verbose) select count(*) from t group by a;
explain(costs off, verbose) select count(*) from t group by b;
explain(costs off, verbose) select count(*) from t group by c;

SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
calls | rows | query
-------+------+------------------------------------------------------------------------------
0 | 0 | SELECT calls, rows, query FROM pg_stat_statements
ORDER BY query COLLATE "C"
1 | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t
2 | 0 | explain(costs off, verbose) select count(*) from t group by a
2 | 0 | explain(costs off, verbose) select count(*) from t group by a;
1 | 0 | explain(costs off, verbose) select count(*) from t group by c
1 | 0 | explain(costs off, verbose) select count(*) from t group by c;
(6 rows)

transformSelectStmt->transformGroupClause->transformGroupClauseExpr->addTargetToGroupList
will produce the same SortGroupClause node for "group by a" and "group by b".

JumbleQuery will jumble Query->groupClause, but RangeTblEntry->groupexprs in
Query->rtable is marked with query_jumble_ignore and therefore excluded from
jumbling.

So "group by a" and "group by" merged into the same entry in
pg_stat_statements,
Is this what we expected?

--
jian
https://www.enterprisedb.com/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2026-01-10 13:15:28 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Japin Li 2026-01-10 12:15:04 Re: GIN pageinspect support for entry tree and posting tree