Re: Wrong results with grouping sets

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Wrong results with grouping sets
Date: 2024-10-10 08:06:11
Message-ID: CAMbWs4-GJuN0pKRYtSGNu7_TOfum3HOFxhKF8Ld3d2iGWwjadQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Oct 10, 2024 at 2:39 PM David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
> create table a(a int);
> explain select * from a where exists(Select 1 from a a2 where a.a =
> a2.a group by a);
> CREATE TABLE
> server closed the connection unexpectedly
>
> TRAP: failed Assert("parse->hasGroupRTE"), File:
> "../src/backend/optimizer/plan/planner.c", Line: 794, PID: 107765

Thank you for the report!

The subquery initially has a valid groupClause, so the parser adds an
RTE_GROUP for it and marks its hasGroupRTE as true. When we pull the
subquery up to the parent level, the RTE_GROUP entry is attached to
the parent. However, the parent query is not marked as hasGroupRTE
because it does not contain any GROUP clauses. So we hit the Assert.

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).

Thanks
Richard

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fredrik Widlert 2024-10-10 08:24:29 Re: Pg17 Crash in Planning (Arrays + Casting + UDF)
Previous Message Daniel Gustafsson 2024-10-10 07:43:27 Re: Allow default \watch interval in psql to be configured