Re: BUG #19649: Qual pushdown into GROUP BY subqueries ignores non-equivalence-preserving references to grouping col

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>
Cc: Andrei Lepikhov <lepihov(at)gmail(dot)com>, 303677365(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, Tender Wang <tndrwang(at)gmail(dot)com>
Subject: Re: BUG #19649: Qual pushdown into GROUP BY subqueries ignores non-equivalence-preserving references to grouping col
Date: 2026-09-22 16:52:43
Message-ID: 1188432.1790095963@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com> writes:
> Refuse to push a non-operand reference to a grouping column below the
> grouping boundary unless the grouping equality is image equality
> (BTEQUALIMAGE_PROC). That covers jsonb, numeric, float8 and similar
> types, and subsumes the old nondeterministic-collation check for
> wrapped references.

The more I think about it, the less I like this solution approach.
The trouble with it is that in exchange for making ill-posed queries
(with no real-world use-cases) seem to have stable semantics, you
are going to cause a disastrous performance regression for perfectly
fine queries that do have real-world use. I can't see us taking
that tradeoff. Especially when the apparently stable semantics are
in fact no such thing, so that there isn't any useful gain from
making the code act that way.

What we really need here, perhaps, is a way to mark functions that
can distinguish values seen as equal by their datatype's default
equality operator. I'm not sure of a good way to do that. If we
did have such a marking, frankly what I would do with it would be
less like "don't push down past aggregation" and more like "throw
an error that this query has undefined results". Otherwise we're
just going to replace bug reports of this shape with bug reports
about the query's result being unstable.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message shihao zhong 2026-09-23 03:43:02 Re: BUG #19705: One NaN box makes a BRIN box_inclusion_ops index omit unrelated rows
Previous Message Tom Lane 2026-09-22 16:28:44 Re: BUG #19713: WindowAgg qual pushdown gives wrong partition count when scale(numeric) distinguishes equal values