Re: [PATCH] Fix grouping-set nulling of variable-free grouping expressions

From: Haibo Yan <tristan(dot)yim(at)gmail(dot)com>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [PATCH] Fix grouping-set nulling of variable-free grouping expressions
Date: 2026-10-23 01:45:05
Message-ID: CABXr29EVOzjAseaNKO5xK2JrhQVP2UA89QfP3xw2A_gDOiNATA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Shihao,

Thanks for confirming, and for the additional examples.

The HAVING case is another good demonstration of why structural
matching should exclude grouping items without a level-zero Var.
The constant in HAVING is independent of the grouped target entry,
so it should not be replaced by a group Var.

I also agree that the now() example should retain the PG18/master
behavior (f, f). The independently written now() expression does
not reference the grouping output merely because it is structurally
equal.

I've tested a prototype combining the two parser rules with v3's
PHV-sharing change, with encouraging results so far. I'll verify
these two examples explicitly and add them to the regression tests
before posting a revision.

I'd still like to hear Tom's thoughts on the level-zero-Var rule,
since that determines the intended semantics of these cases.

Thanks,
Haibo

On Tue, Oct 20, 2026 at 5:48 PM shihao zhong <zhong950419(at)gmail(dot)com> wrote:
>
> Hi Haibo,
>
> I agree with both rules. On your CUBE example, 17 and 18 also give 2 rows,
> so master's 4 is right.
>
> v3 alone has one more problem. SELECT 1 AS x GROUP BY ROLLUP(x) HAVING 1
> IS NOT NULL returns 2 rows on master but 1 with v3. The parser turns the
> 1 in HAVING into a GROUP Var.
>
> A question on (b). SELECT now() IS NULL AS n GROUP BY ROLLUP(now())
> gives f and t on 17 and with v3, but f and f on 18 and master. (b)
> should keep f and f, which seems fine to me.
>
> Thanks,
> Shihao
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Henson Choi 2026-10-23 01:58:29 Re: [DEPARSE] Operators on ROW() constructors read back as row comparisons
Previous Message shihao zhong 2026-10-23 01:36:20 Re: json/jsonb cleanup + FmgrInfo caching