| From: | Richard Guo <rguo(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Fix eager aggregation grouping on cross-type join keys |
| Date: | 2026-10-05 23:52:21 |
| Message-ID: | E1xDsTl-00000000TZH-0XZe@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Fix eager aggregation grouping on cross-type join keys
When a Var of the relation to be partially aggregated is known equal
to a GROUP BY expression through an EC, get_expression_sortgroupref()
let it reuse that expression's SortGroupClause. If the two are of
different types, as with an int2 grouping key joined to an int4
column, the Var was then grouped using the other type's equality
operator, which could put unequal values into the same group and give
wrong results.
To fix, accept only EC members of the same type as the grouping
expression. A cross-type Var is then treated like any other join key
and gets a SortGroupClause built for its own type.
Reported-by: Robert Haas <robertmhaas(at)gmail(dot)com>
Author: Richard Guo <guofenglinux(at)gmail(dot)com>
Discussion: https://postgr.es/m/CA+Tgmob7iSM9YkRM44VjUDuaCchW-fY54MV5njpTZTL9uNyV4w@mail.gmail.com
Backpatch-through: 19
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/d764d61af3160f725ac087ccc05d9ccf03af8312
Modified Files
--------------
src/backend/optimizer/util/relnode.c | 4 +++
src/test/regress/expected/eager_aggregate.out | 44 +++++++++++++++++++++++++++
src/test/regress/sql/eager_aggregate.sql | 23 ++++++++++++++
3 files changed, 71 insertions(+)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Amit Langote | 2026-10-06 00:04:57 | pgsql: Fix possible crash when RI fast-path metadata is invalidated mid |
| Previous Message | Masahiko Sawada | 2026-10-05 23:17:44 | pgsql: Fix parallel autovacuum workers ignoring track_cost_delay_timing |