Re: Wrong results with grouping sets

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-24 20:21:05
Message-ID: 4030683.1771964465@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 Mon, Feb 23, 2026 at 11:48 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> How can that possibly be safe?

> Ugh. I'm not sure what I was thinking there. Deleting an RTE from
> the middle of the rtable is definitely taboo, as it shifts the indexes
> and can silently corrupt any Var nodes in the query tree that
> reference those later RTEs. Also, relying on the RTE_GROUP happening
> to be the last entry in the list is extremely fragile and just trouble
> waiting to happen.

Exactly. I'm not sure it's actively broken now (I spent a bit of
effort looking for a counterexample, and didn't find one), but it's
really far too fragile.

> Attached is the patch that converts the RTE into an RTE_RESULT.

LGTM.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Champion 2026-02-24 20:29:02 Re: pgsql: libpq: Grease the protocol by default
Previous Message Zsolt Parragi 2026-02-24 20:09:35 Re: pg_dumpall --roles-only interact with other options