Re: Show estimated number of groups for IncrementalSort in EXPLAIN

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Ilia Evdokimov <ilya(dot)evdokimov(at)tantorlabs(dot)com>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Show estimated number of groups for IncrementalSort in EXPLAIN
Date: 2026-06-22 22:39:35
Message-ID: CAApHDvrdzpJfPVdbSnBpyPVzo67KJ-w-WvLLr=xRfit_FKDovw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 11 Jun 2026 at 03:50, Ilia Evdokimov
<ilya(dot)evdokimov(at)tantorlabs(dot)com> wrote:
> In [0], a question was raised whether we should expose IncrementalSort group estimation in EXPLAIN, as we did for Memoize. Knowing the estimated number of groups helps understand why the planner chose IncrementalSort whether a bad estimate is to blame for a sub-optimal plan.
> [0]: https://www.postgresql.org/message-id/6642af90-561c-4f0c-9d5b-7e288e6e7f84%40gmail.com

I think it makes sense to have this information in EXPLAIN.

A couple of things about the patch:

1. I think the new est_input_groups field should be Cardinality rather
than double. Various other Path types and Plan nodes call this
"numGroups". I don't see any reason to deviate from that.
2. The header comment for cost_incremental_sort needs to be updated to
mention that p_input_groups may be passed as non-NULL to provide the
caller with the estimated number of sort groups.

David

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-06-22 23:08:00 Re: psql: Fix CREATE SCHEMA scanning of nested routine bodies
Previous Message Bharath Rupireddy 2026-06-22 22:39:00 Re: Add a hook for handling logical decoding messages on subscribers.