agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix qual pushdown past grouping through simple CASE
Date: Wed, 02 Sep 2026 06:35:03 +0000
Message-ID: <E1x1eYo-000000038vv-0VRT@gemulon.postgresql.org> (raw)
Fix qual pushdown past grouping through simple CASE
Commit 44fb59fc6 taught the grouping-conflict walker to treat the arg
of a simple CASE as a direct operand of each WHEN comparison, but it
only checked the collation, on the assumption that the WHEN operator
is always the type-default "=" and thus matches the grouping eqop.
That assumption fails once the arg is relabeled to another type: the
WHEN then compares under that type's "=", which need not agree with
the grouping equality. For instance, with a DISTINCT over a citext
column, a qual such as "CASE t::text WHEN 'A' THEN ..." was pushed
below the Unique, although the equivalent "t::text = 'A'" is correctly
kept above it.
Instead of special-casing the arg, have the walker bind a Var arg
while walking the WHEN conditions and resolve each CaseTestExpr to it,
so that the arg is checked exactly as each WHEN uses it: with the
opfamily and collation checks of a direct operand when the WHEN is a
comparison, and as a non-operand reference otherwise. A non-Var arg
is walked once as a non-operand, as before. The CaseTestExpr in an
ArrayCoerceExpr's elemexpr and a JsonConstructorExpr's coercion stand
for something else and are left alone.
Reported-by: Tender Wang <tndrwang@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
Discussion: https://postgr.es/m/CAHewXNkvGTOgijRLjmudpg=wz0d-J8ChY2o7ksh3Be+Q_Bxwog@mail.gmail.com
Backpatch-through: 18
Branch
------
REL_18_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/dd7c135bb97ec7a5dad09fa9e1e2dd9c044ceee8
Modified Files
--------------
src/backend/optimizer/util/clauses.c | 127 +++++++++++++++++--------
src/test/regress/expected/collate.icu.utf8.out | 35 +++++++
src/test/regress/expected/subselect.out | 27 ++++++
src/test/regress/sql/collate.icu.utf8.sql | 12 +++
src/test/regress/sql/subselect.sql | 11 +++
5 files changed, 171 insertions(+), 41 deletions(-)
view thread (3+ messages)
Message-ID: <E1x1eYo-000000038vv-0VRT@gemulon.postgresql.org>
Permalink: ../E1x1eYo-000000038vv-0VRT@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1x1eYo-000000038vv-0VRT@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: rguo@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Fix qual pushdown past grouping through simple CASE
In-Reply-To: <E1x1eYo-000000038vv-0VRT@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox