From: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix eager aggregation grouping on cross-type join keys
Date: Mon, 05 Oct 2026 23:52:21 +0000
Message-ID: <E1xDsTl-00000000TZN-0nbx@gemulon.postgresql.org> (raw)
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(+)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: rguo@postgresql.org
Subject: Re: pgsql: Fix eager aggregation grouping on cross-type join keys
In-Reply-To: <E1xDsTl-00000000TZN-0nbx@gemulon.postgresql.org>
References: <E1xDsTl-00000000TZN-0nbx@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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