Whatsonyourmind commented on issue #21120:
URL: https://github.com/apache/datafusion/issues/21120#issuecomment-4182731153

   A few notes on the Selinger-style default analyzer for the planned work:
   
   For **selectivity estimation** of comparison predicates (`col > const`), the 
classic approach when histograms are unavailable is the uniform distribution 
assumption with min/max bounds:
   
   ```
   selectivity(col > c) = (max - c) / (max - min)    when min ≤ c ≤ max
   selectivity(col > c) = 0                           when c > max
   selectivity(col > c) = 1                           when c < min
   ```
   
   For compound predicates, the independence assumption gives:
   - `AND`: multiply selectivities
   - `OR`: `1 - (1 - s1)(1 - s2)`  
   - `NOT`: `1 - s`
   
   For **NDV propagation through expressions**: arithmetic operations like `col 
+ 1` preserve NDV exactly. For `col1 + col2`, the upper bound on NDV is 
`min(NDV1 * NDV2, row_count)`. For functions like `FLOOR(col)`, NDV can only 
decrease: `NDV_out ≤ NDV_in`. For `date_trunc('month', ts_col)`, NDV can be 
estimated as `(max - min) / interval_size`.
   
   One design consideration: the chain-of-responsibility pattern should 
propagate **confidence levels** alongside estimates. A histogram-based analyzer 
might return `(selectivity=0.23, confidence=High)`, while a fallback heuristic 
returns `(selectivity=0.20, confidence=Low)`. The optimizer can then weight its 
cost model decisions by confidence -- preferring plans that are robust to 
estimation error when confidence is low.


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