| From: | "Matheus Alcantara" <matheusssilv97(at)gmail(dot)com> |
|---|---|
| To: | "Aleksander Alekseev" <aleksander(at)tigerdata(dot)com>, <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
| Cc: | <alpkeles99(at)gmail(dot)com>, "Richard Guo" <guofenglinux(at)gmail(dot)com> |
| Subject: | Re: BUG #19772: ERROR: corrupt MVNDistinct entry for GROUP BY c0, ROLLUP (abs(c0)) with ndistinct statistics |
| Date: | 2026-11-16 16:07:34 |
| Message-ID: | DMWRJIXJZICW.35POJKKJA72UM@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi Aleksander,
Thanks for the review!
On Mon Nov 16, 2026 at 7:45 AM -03, Aleksander Alekseev wrote:
>> The attached patch fixes this by also stripping the grouping step's RT
>> index wherever selfuncs.c already strips the outer join nullingrels
>> before looking up statistics.
>
> I reviewed v1. It applies cleanly and the tests pass. Your analysis
> matches what I see. The three new cases do fail with "corrupt
> MVNDistinct entry" without the fix.
>
> However, only add_unique_group_var() is covered. If I revert the
> examine_variable() and estimate_multivariate_bucketsize() but keep the
> tests, the whole regression suite still passes.
Right. (a+1) has the same number of distinct values as a, so falling
back to the column's statistics gives the same estimate either way. v2
adds tests with GROUP BY ROLLUP ((d % 2)), using statistics on (d % 2)
in one and an expression index in the other. Both estimate 3 groups with
the fix and 21 with the examine_variable() change reverted.
I think that the estimate_multivariate_bucketsize() change can't
actually take effect, because hash join keys are planned below the
grouping step and never carry its RT index. v2 drops that change and
keeps stripping only outer-join nullingrels there.
v2 attached.
--
Matheus Alcantara
EDB: https://www.enterprisedb.com
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Ignore-grouping-step-nullingrels-when-looking-up-.patch | text/plain | 8.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andres Freund | 2026-11-16 16:29:07 | Re: PG 18 JIT regression: int4range hash breaks multi-key GROUP BY |
| Previous Message | Melanie Plageman | 2026-11-16 16:03:25 | Re: PostgreSQL 18.6/17.11: standby PANIC on restart after VM truncation |