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

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Propagate stadistinct through GROUP BY/DISTINCT in subqueries and CTEs
Date: 2026-07-08 00:57:24
Message-ID: CAMbWs48b4hrc3kzf4Ec3Wb2DMOvHzZ-9UbGe9H3Y0TXyCNJ6XQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jul 7, 2026 at 2:31 PM Richard Guo <guofenglinux(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-07-08 01:38:54 Re: [PATCH] Don't call ereport(ERROR) from recovery target GUC assign hooks
Previous Message Jeff Davis 2026-07-08 00:56:57 Re: Small patch to improve safety of utf8_to_unicode().