Returns `Some(1.0 / distinct_count)` when the filter demonstrably collapsed a non-singleton interval down to a single point, i.e. an equality predicate was applied. Returns `None` in all other cases, signalling that the caller should fall back to [`cardinality_ratio`]. The `initial_interval` guard prevents double-counting selectivity when the column statistics already described a singleton befor
(
initial_interval: &Interval,
target_interval: &Interval,
distinct_count: usize,
)
| 271 | /// additional selectivity has been gained and the `1 / NDV` shortcut must not |
| 272 | /// fire. |
| 273 | fn singleton_selectivity( |
| 274 | initial_interval: &Interval, |
| 275 | target_interval: &Interval, |
| 276 | distinct_count: usize, |
| 277 | ) -> Option<f64> { |
| 278 | // The target must have collapsed to a single non-null value. |
| 279 | if distinct_count == 0 |
| 280 | || target_interval.lower().is_null() |
| 281 | || target_interval.lower() != target_interval.upper() |
| 282 | { |
| 283 | return None; |
| 284 | } |
| 285 | |
| 286 | // Only treat this as a newly-applied equality filter when the initial |
| 287 | // interval was not already that same singleton. If it was, the stats |
| 288 | // already encoded this restriction and applying 1/NDV again would |
| 289 | // under-estimate the row count. |
| 290 | let initial_is_same_singleton = !initial_interval.lower().is_null() |
| 291 | && initial_interval.lower() == initial_interval.upper() |
| 292 | && initial_interval.lower() == target_interval.lower(); |
| 293 | |
| 294 | if initial_is_same_singleton { |
| 295 | return None; |
| 296 | } |
| 297 | |
| 298 | Some(1.0 / distinct_count as f64) |
| 299 | } |
| 300 | |
| 301 | /// This function calculates the filter predicate's selectivity by comparing |
| 302 | /// the initial and pruned column boundaries. Selectivity is defined as the |
searching dependent graphs…