hcrosse opened a new pull request, #27627:
URL: https://github.com/apache/datafusion/pull/27627

   ## Which issue does this PR close?
   
   - Closes #27626.
   
   ## Rationale for this change
   
   `FilterExec` previously capped unrelated columns' `null_count` at the 
filtered row count instead of scaling it by the filter selectivity. After a 
selective filter on an unrelated column, a nullable join key could appear 
almost entirely null, collapsing its estimated non null count to `0` or `1` and 
inflating downstream `HashJoinExec` cardinality estimates by hundreds of times 
(for example from `Inexact(285)` to `Inexact(60200)` when actual output dropped 
from `140` to `0`).
   
   ## What changes are included in this PR?
   
   - Added `scale_null_count_at_rows` in 
`datafusion/physical-plan/src/filter.rs` to scale `null_count` by the filter 
selectivity and cap it at `filtered_num_rows`, keeping `Exact(0)` exact when 
either the input null count or the filtered row count is `Exact(0)`.
   - Updated all three filter selectivity statistics paths 
(`FilterExec::statistics_helper`, `null_check_statistics`, and 
`collect_new_statistics`) to pass the original `null_count` precision into 
`scale_null_count_at_rows` rather than capping with `cap_at_rows`.
   - Left `distinct_count` handling untouched (tracked separately in #26052) 
and left `statistics_under_fetch` as `cap_at_rows`.
   
   ## What is the testing strategy for this PR?
   
   - Updated the four existing filter statistics unit tests in 
`datafusion/physical-plan/src/filter.rs` whose expected `null_count` values 
reflected the old row count cap.
   - Added unit tests in `datafusion/physical-plan/src/filter.rs` covering 
`null_count` scaling and `Exact(0)` preservation across all three paths, helper 
edge cases (`Exact(0)`, `Inexact(0)`, `Absent`, selectivity `0.0` and `1.0`), 
and the `HashJoinExec` cardinality regression.
   
   ## Are there any user-facing changes?
   
   No API changes. `EXPLAIN` statistics for `FilterExec` now report selectivity 
scaled `null_count` on unrelated columns, and joins above filtered nullable 
keys receive more accurate cardinality estimates.
   


-- 
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