Richard Guo <[email protected]> writes:
> On Thu, Oct 10, 2024 at 4:06 PM Richard Guo <[email protected]> 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