pgsql: Fix eager aggregation below volatile join clauses

From: Richard Guo <rguo(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix eager aggregation below volatile join clauses
Date: 2026-10-29 06:34:03
Message-ID: E1xMJi7-00000001DtE-1rL0@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)gmail(dot)com>
Reviewed-by: Manu <manuelreyesbravo(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAGRkXqSc_qtpuPm34qoS1z0LVx4+Hc+JcJkbDEVC=z2ai4VQ1w@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/27c844034f827b3910bc8a358780c6609ba87a41

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

Browse pgsql-committers by date

  From Date Subject
Previous Message Jeff Davis 2026-10-29 06:26:37 pgsql: PG 19: Add migration note about tsearch & pg_trgm.