pgsql: Show estimated number of groups for Incremental Sort in EXPLAIN

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Show estimated number of groups for Incremental Sort in EXPLAIN
Date: 2026-08-11 01:30:27
Message-ID: E1wtbJy-000000003d5-0SsV@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Show estimated number of groups for Incremental Sort in EXPLAIN

Incremental Sort's costs heavily depend on the estimated number of input
groups with equal presorted key values. Overestimations can cause the
planner to choose Incremental Sort over Sort when Sort would have
been a better choice.

Here, we add the planner's estimate to EXPLAIN to allow easier
understanding of why Incremental Sort has been chosen.

Author: Ilia Evdokimov <ilya(dot)evdokimov(at)tantorlabs(dot)com>
Reviewed-by: Enrique Sánchez <enriqueesanchz(at)gmail(dot)com>
Reviewed-by: David Rowley <dgrowleyml(at)gmail(dot)com>
Reviewed-by: solai v <solai(dot)cdac(at)gmail(dot)com>
Discussion: https://postgr.es/m/10682fef-3748-43f5-a932-7adcdd9bd2b8%40tantorlabs.com

Branch
------
master

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

Modified Files
--------------
doc/src/sgml/perform.sgml | 1 +
src/backend/commands/explain.c | 5 +++++
src/backend/optimizer/path/costsize.c | 16 +++++++++++++---
src/backend/optimizer/plan/createplan.c | 4 +++-
src/backend/optimizer/util/pathnode.c | 6 ++++--
src/include/nodes/pathnodes.h | 1 +
src/include/nodes/plannodes.h | 2 ++
src/include/optimizer/cost.h | 3 ++-
8 files changed, 31 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2026-08-11 07:42:18 pgsql: Use frontend logging API in fe_utils/string_utils.c
Previous Message Tom Lane 2026-08-10 21:00:10 pgsql: Stamp 14.24.