Re: Propagate stadistinct through GROUP BY/DISTINCT in subqueries and CTEs - Mailing list pgsql-hackers

From Richard Guo
Subject Re: Propagate stadistinct through GROUP BY/DISTINCT in subqueries and CTEs
Date
Msg-id CAMbWs48b4hrc3kzf4Ec3Wb2DMOvHzZ-9UbGe9H3Y0TXyCNJ6XQ@mail.gmail.com
Whole thread
List 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



pgsql-hackers by date:

Previous
From: Jeff Davis
Date:
Subject: Re: Small patch to improve safety of utf8_to_unicode().
Next
From: Fujii Masao
Date:
Subject: Re: [PATCH] Don't call ereport(ERROR) from recovery target GUC assign hooks