>Original
>From: shihao zhong <[email protected]>
>Date: 2026-10-11 10:38
>To: ZizhuanLiu X-MAN <[email protected]>
>Cc: pgsql-hackers <[email protected]>, jian he 
><[email protected]>, tgl <[email protected]>, Guo 
><[email protected]>
>Subject: Re: examine_variable ignored CollateExpr
>
>Hi Zizhuan,
>
>Thanks for v5. My example is fixed, I get rows=100 again. The
>regression tests pass, and I could not measure any change in
>planning time for varchar columns.
>
>One more issue 
>
>  CREATE TABLE t (a text);
>  INSERT INTO t SELECT chr(65 + g % 52) || g
>    FROM generate_series(1, 5200) g;
>  CREATE STATISTICS s ON (left(a, 1) COLLATE "C") FROM t;
>  ANALYZE t;
>  EXPLAIN SELECT * FROM t WHERE left(a, 1) = 'A';
>
>On master I get rows=100, with v5 I get rows=26. I think the retry
>only runs when the query has the COLLATE, not when only the
>statistics expression has it.
>
>v5 also dropped the tests that v1 had. Could you add them back,
>with this case and my earlier one?
>
>Thanks,
>Shihao       

Hi, Shihao,hackers

Thank you for your prompt and constructive feedback.

I've updated the code to avoid unnecessary comparisons on retry.
It now separately tracks whether node, indexpr, and statexpr have 
a topmost RelabelType associated with COLLATE, and uses these 
flags to determine which comparisons are necessary:
  - indexpr is compared only if basenode_is_topmost_relabeltype or 
indexkey_is_topmost_relabeltype is true.
  - statexpr is compared only if basenode_is_topmost_relabeltype or 
statexpr_is_topmost_relabeltype is true.

All the issues you mentioned have been addressed, and the missing test cases 
have been added. 
The corresponding regression tests and expected output have also been updated 
in the .sql and .out files.

Thanks again for your review and suggestions.

regards,           
--                 
ZizhuanLiu (X-MAN) 
[email protected]

Attachment: v6-0001-Fix-RelabelType-handling-in-statistics-lookup.patch
Description: Binary data

Reply via email to