asolimando opened a new issue, #21109:
URL: https://github.com/apache/datafusion/issues/21109

   ## Is your feature request related to a problem or challenge?
   
   In #21077, we set `distinct_count` to `Exact(1)` when a filter predicate 
collapses a column interval to a single value. This works for numeric types 
(Int32, Float64, etc.) but not for strings (Utf8, Utf8View, LargeUtf8).
   
   The root cause is that 
[`next_value_helper()`](https://github.com/apache/datafusion/blob/f734ec54dc1b93b964bd69cfeca725b117f16244/datafusion/expr-common/src/interval_arithmetic.rs#L1233)
 in `interval_arithmetic.rs` has no implementation for string types - it 
returns the value unchanged, which prevents the constraint propagation solver 
from collapsing the interval.
   
   For example, `WHERE name = 'hello'` should produce NDV=Exact(1) but 
currently stays at the original Inexact NDV.
   
   ## Describe the solution you'd like
   
   Detect equality predicates directly in 
[`collect_new_statistics`](https://github.com/apache/datafusion/blob/f734ec54dc1b93b964bd69cfeca725b117f16244/datafusion/physical-plan/src/filter.rs#L808)
 (pattern-match `BinaryExpr` with `Operator::Eq` + `Column` + `Literal`), 
bypassing interval analysis for the NDV computation.
   
   ## Describe alternatives you've considered
   
   Implement `next_value` for strings in 
[`interval_arithmetic.rs`](https://github.com/apache/datafusion/blob/f734ec54dc1b93b964bd69cfeca725b117f16244/datafusion/expr-common/src/interval_arithmetic.rs#L1233).
 This is non-trivial since string ordering depends on locale/collation (see 
PostgreSQL's [collation 
support](https://www.postgresql.org/docs/current/collation.html) for 
reference), making a universal "next string" ill-defined. That said, it would 
benefit other interval-based optimizations as well.
   
   ## Additional context
   
   - Part of #20766
   - Related PR: #21077 (NDV=Exact(1) for numeric types)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to