pgsql: Add an enable_groupagg GUC parameter

From: Richard Guo <rguo(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add an enable_groupagg GUC parameter
Date: 2026-07-09 00:45:23
Message-ID: E1whctG-000E8i-35@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add an enable_groupagg GUC parameter

We've long had enable_hashagg to discourage hashed aggregation, but
there was no equivalent for grouping that works by reading presorted
input. That's handy when investigating planner cost misestimates, and
as an escape hatch when a sorted grouping plan is chosen over a much
cheaper hashed one.

enable_groupagg (on by default) covers the GroupAggregate and Group
nodes, the sort-based Unique step used for DISTINCT and semijoin
unique-ification, and the sorted mode of SetOp. It isn't a hard
switch; it only bumps disabled_nodes, so plans with no other choice
are still produced.

Several regression and module tests had been setting enable_sort off,
and one enable_indexscan off, only to force a hashed plan. Use
enable_groupagg there instead, where that was the real intent. In
union.sql this also lets us test the hashed UNION path, which we had
no way to reach before.

Author: Tatsuro Yamada <yamatattsu(at)gmail(dot)com>
Co-authored-by: Richard Guo <guofenglinux(at)gmail(dot)com>
Reviewed-by: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Reviewed-by: David Rowley <dgrowleyml(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAOKkKFvYHSEsFazkrf9bRH14p-H27XMaqbZfRYjS6EHBruvZMQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e01b23b84e4346c1941e2aad78e3d80a5498038d

Modified Files
--------------
contrib/hstore/expected/hstore.out | 4 +--
contrib/hstore/sql/hstore.sql | 4 +--
contrib/ltree/expected/ltree.out | 4 +--
contrib/ltree/sql/ltree.sql | 4 +--
doc/src/sgml/config.sgml | 14 ++++++++
src/backend/optimizer/path/costsize.c | 33 ++++++++++++++++---
src/backend/optimizer/util/pathnode.c | 20 ++++++++++++
src/backend/utils/misc/guc_parameters.dat | 7 ++++
src/backend/utils/misc/postgresql.conf.sample | 1 +
src/include/optimizer/cost.h | 1 +
.../modules/injection_points/expected/hashagg.out | 2 +-
src/test/modules/injection_points/sql/hashagg.sql | 2 +-
src/test/regress/expected/aggregates.out | 10 +++---
src/test/regress/expected/groupingsets.out | 8 ++---
src/test/regress/expected/jsonb.out | 6 ++--
src/test/regress/expected/multirangetypes.out | 4 +--
src/test/regress/expected/rangetypes.out | 4 +--
src/test/regress/expected/select_distinct.out | 4 +--
src/test/regress/expected/subselect.out | 2 +-
src/test/regress/expected/sysviews.out | 3 +-
src/test/regress/expected/union.out | 37 ++++++++++++++--------
src/test/regress/sql/aggregates.sql | 10 +++---
src/test/regress/sql/groupingsets.sql | 8 ++---
src/test/regress/sql/jsonb.sql | 6 ++--
src/test/regress/sql/multirangetypes.sql | 4 +--
src/test/regress/sql/rangetypes.sql | 4 +--
src/test/regress/sql/select_distinct.sql | 4 +--
src/test/regress/sql/subselect.sql | 2 +-
src/test/regress/sql/union.sql | 16 +++++-----
29 files changed, 153 insertions(+), 75 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-07-09 00:57:27 Re: pgsql: Refactor how some aux processes advertise their ProcNumber
Previous Message Fujii Masao 2026-07-09 00:13:26 pgsql: doc: Fix data checksum progress reporting documentation