From: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix eager aggregation below volatile join clauses
Date: Thu, 29 Oct 2026 06:34:03 +0000
Message-ID: <E1xMJi7-00000001DtG-22XZ@gemulon.postgresql.org> (raw)
Fix eager aggregation below volatile join clauses
Eager aggregation could push a partial aggregation down to a relation
that is later joined using a join clause containing volatile
functions. The clause is then evaluated once per group rather than
once per input row, which changes the number of times the function is
executed.
To fix, refuse to build grouped paths for a relation if any of its
join clauses contains volatile functions.
Back-patch to v19, where eager aggregation was introduced.
Author: shihao zhong <zhong950419@gmail.com>
Reviewed-by: Manu <manuelreyesbravo@gmail.com>
Discussion: https://postgr.es/m/CAGRkXqSc_qtpuPm34qoS1z0LVx4+Hc+JcJkbDEVC=z2ai4VQ1w@mail.gmail.com
Backpatch-through: 19
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/0c6e0437110dd6ceb14fdca5b323bc1b058a13cf
Modified Files
--------------
src/backend/optimizer/util/relnode.c | 13 +++++++++++++
src/test/regress/expected/eager_aggregate.out | 20 ++++++++++++++++++++
src/test/regress/sql/eager_aggregate.sql | 7 +++++++
3 files changed, 40 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 below volatile join clauses
In-Reply-To: <E1xMJi7-00000001DtG-22XZ@gemulon.postgresql.org>
References: <E1xMJi7-00000001DtG-22XZ@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