Re: Show estimated number of groups for IncrementalSort in EXPLAIN - Mailing list pgsql-hackers

From David Rowley
Subject Re: Show estimated number of groups for IncrementalSort in EXPLAIN
Date
Msg-id CAApHDvrdzpJfPVdbSnBpyPVzo67KJ-w-WvLLr=xRfit_FKDovw@mail.gmail.com
Whole thread
Responses Re: Show estimated number of groups for IncrementalSort in EXPLAIN
List pgsql-hackers
On Thu, 11 Jun 2026 at 03:50, Ilia Evdokimov
<ilya.evdokimov@tantorlabs.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
estimateis 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



pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: Add a hook for handling logical decoding messages on subscribers.
Next
From: Christophe Pettus
Date:
Subject: Re: The PostgreSQL C Dialect