Re: Unsafe qual pushdown through DISTINCT with simple CASE expressions - Mailing list pgsql-hackers

From Tender Wang
Subject Re: Unsafe qual pushdown through DISTINCT with simple CASE expressions
Date
Msg-id CAHewXNm-VsGpyKOhXH9PEdT9_Sry2krj1-WX2F1MuuXMjrTtGg@mail.gmail.com
Whole thread
List pgsql-hackers
Richard Guo <guofenglinux@gmail.com> 于2026年8月28日周五 10:20写道:
> I think it'd be better to avoid this duplication.  So I'd like to take
> the approach used elsewhere in planner for the same placeholder: while
> walking the WHEN conditions, the walker binds a Var arg in the context
> and resolves each CaseTestExpr to it.  The Var is then checked as each
> WHEN uses it.  This is how eval_const_expressions() handles the
> CaseTestExpr nodes.
>
> Attached is the patch doing that.

I took a look at the existing handling of CaseTestExpr in the planner,
and it works as you described.

I noticed that you added special handling for ArrayCoerceExpr in
grouping_conflict_walker(), but the current regression tests don't
exercise this new branch.
I think it would be better to add a test case to cover it.

For example:

CREATE TEMP TABLE case_array_test (a int[]);

EXPLAIN (COSTS OFF)
SELECT *
FROM (SELECT DISTINCT a FROM case_array_test) s
WHERE CASE a::bigint[]
WHEN ARRAY[1::bigint] THEN true
ELSE false
END;

The rest looks good to me.

--
Thanks,
Tender Wang



pgsql-hackers by date:

Previous
From: Koshino Taiki
Date:
Subject: Re: doc: Reformat SELECT queries using GRAPH_TABLE
Next
From: Chao Li
Date:
Subject: Re: REPACK (CONCURRENTLY) fails when replica identity index is dropped