| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Richard Guo <guofenglinux(at)gmail(dot)com> |
| Cc: | David Rowley <dgrowleyml(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Wrong results with grouping sets |
| Date: | 2026-02-23 14:48:27 |
| Message-ID: | 3472344.1771858107@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Richard Guo <guofenglinux(at)gmail(dot)com> writes:
> On Thu, Oct 10, 2024 at 4:06 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
>> While we can fix this issue by propagating the hasGroupRTE mark from
>> the EXISTS subquery to the parent, a better fix might be to remove the
>> subquery's RTE_GROUP entry, since we have dropped the subquery's
>> groupClause before the pull-up (see simplify_EXISTS_query).
> Here is the patch.
I happened to notice ffe12d1d2 after David mentioned
simplify_EXISTS_query in another thread, and nearly fell off my chair
when I read this bit:
query->rtable = list_delete_cell(query->rtable, lc);
How can that possibly be safe? It will change the rangetable index of
every following RTE. It might appear to work as long as the RTE_GROUP
RTE is always last. But I don't think you can rely on that, or should
rely on it even if it does happen to still be always true even after
query rewrite and other early-planning manipulations.
A safer way might be to convert the RTE into an unreferenced
RTE_RESULT, or some other innocuous RTE type.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bertrand Drouvot | 2026-02-23 15:22:22 | Re: Check for memset_explicit() and explicit_memset() |
| Previous Message | Daniel Gustafsson | 2026-02-23 14:47:57 | Re: DOCS - Server Applications [option] should be [option...] |