pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix eager aggregation grouping on cross-type join keys
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix eager aggregation grouping on cross-type join keys
@ 2026-10-05 23:52 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Guo @ 2026-10-05 23:52 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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@gmail.com>
Author: Richard Guo <guofenglinux@gmail.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(+)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix eager aggregation grouping on cross-type join keys
@ 2026-10-05 23:52 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Guo @ 2026-10-05 23:52 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CA+Tgmob7iSM9YkRM44VjUDuaCchW-fY54MV5njpTZTL9uNyV4w@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0697c84a3e10f265167b46958b6b711c61c423fe

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(+)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-10-05 23:52 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-05 23:52 pgsql: Fix eager aggregation grouping on cross-type join keys Richard Guo <rguo@postgresql.org>
2026-10-05 23:52 pgsql: Fix eager aggregation grouping on cross-type join keys Richard Guo <rguo@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox