Commit 0f7bddd
authored
fix(common): preserve an exact zero through filter selectivity estimation (#23936)
## Which issue does this PR close?
- Part of #8227.
## Rationale for this change
`Precision::with_estimated_selectivity` always demoted to inexact, so
`Exact(0)` became `Inexact(0)`. Scaling zero by any selectivity is still
exactly zero: filtering a provably empty input cannot produce rows.
Because operators widen exact to inexact, emptiness could not propagate
up a plan through statistics at all, it was lost at the first
`FilterExec`. That operator already preserved the exact zero for a
contradictory predicate and for column byte sizes, so the same fact came
out exact or inexact depending on the path taken.
This is the same reasoning as #23670, which stops
`FileScanConfig::statistics()` demoting an exact zero when a filter is
present, applied one level up. The two are independent, but together
they let a proof of emptiness survive from the scan through the filter.
## What changes are included in this PR?
- `with_estimated_selectivity` returns an exact zero unchanged.
`Inexact(0)` is untouched: an estimate of zero is not a proof of zero.
- `scale_byte_size` in `filter.rs` is removed, subsumed by the above.
## Are these changes tested?
Yes. A unit test for the method, and a `FilterExec` test that a
satisfiable predicate over an exactly empty input keeps `num_rows`,
`total_byte_size` (proving that `scale_byte_size` can be safely removed)
and column `byte_size` exact.
`test_filter_statistics_empty_input_equality_ndv_zero` asserted
`Inexact(0)` and now asserts `Exact(0)`, which is expected.
## Are there any user-facing changes?
No breaking changes. `Precision::with_estimated_selectivity` is public
and keeps its signature, but its documented contract changes: it
previously stated it would always return inexact statistics, and it now
preserves an exact zero. Callers relying on the old wording will see
`Exact(0)` where they saw `Inexact(0)`. This is an improvement and could
be arguably considered a bug-fix, so I consider this contract change
justified.
`FilterExec` over a provably empty input therefore reports exact
statistics, visible in `EXPLAIN` output that shows statistics.
----
Disclaimer: I used AI to assist in the code generation, I have manually
reviewed the output and it matches my intention and understanding.1 parent 95226ac commit 0f7bddd
2 files changed
Lines changed: 86 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
| 198 | + | |
| 199 | + | |
199 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
200 | 204 | | |
201 | 205 | | |
202 | 206 | | |
| |||
1202 | 1206 | | |
1203 | 1207 | | |
1204 | 1208 | | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
1205 | 1247 | | |
1206 | 1248 | | |
1207 | 1249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | | - | |
| 387 | + | |
| 388 | + | |
388 | 389 | | |
389 | 390 | | |
390 | 391 | | |
| |||
1030 | 1031 | | |
1031 | 1032 | | |
1032 | 1033 | | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
1043 | 1034 | | |
1044 | 1035 | | |
1045 | 1036 | | |
| |||
1133 | 1124 | | |
1134 | 1125 | | |
1135 | 1126 | | |
1136 | | - | |
1137 | | - | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
1138 | 1130 | | |
1139 | 1131 | | |
1140 | 1132 | | |
| |||
2909 | 2901 | | |
2910 | 2902 | | |
2911 | 2903 | | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
| 2915 | + | |
| 2916 | + | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
| 2921 | + | |
| 2922 | + | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
2912 | 2940 | | |
2913 | 2941 | | |
2914 | 2942 | | |
| |||
2963 | 2991 | | |
2964 | 2992 | | |
2965 | 2993 | | |
2966 | | - | |
| 2994 | + | |
2967 | 2995 | | |
2968 | 2996 | | |
2969 | 2997 | | |
2970 | 2998 | | |
2971 | | - | |
| 2999 | + | |
2972 | 3000 | | |
2973 | 3001 | | |
2974 | 3002 | | |
| |||
0 commit comments