pgsql: Fix qual pushdown past grouping through simple CASE
pgsql: Fix qual pushdown past grouping through simple CASE
От:
Richard Guo <rguo@postgresql.org>
Дата:
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 Author: Richard Guo Reviewed-by: Tender Wang Reviewed-by: Ewan Young 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(-)