Re: Propagate stadistinct through GROUP BY/DISTINCT in subqueries and CTEs

Richard Guo <guofenglinux@gmail.com>

From: Richard Guo <guofenglinux@gmail.com>
To: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-07-08T00:57:24Z
Lists: pgsql-hackers
On Tue, Jul 7, 2026 at 2:31 PM Richard Guo <guofenglinux@gmail.com> wrote:
> Attached is v2 addressing this.  For a single grouping key, at most
> one NULL group remains, so we set it to 1 / (ndistinct + 1).  With
> multiple grouping keys, the surviving NULL count is underdetermined,
> so we approximate it as zero; NULLs collapse far more aggressively
> than non-NULLs, so the real fraction is well below the base table's,
> and erring low keeps estimates on the hash-join-favoring side.

I've pushed the v2 patch.

- Richard