Skip to content

Commit a53c4f4

Browse files
committed
fix: do not infer semi/anti join coverage from range-bounded distinct counts
`max_distinct_count` falls back to the cardinality of `[min, max]` when a column has no `distinct_count`. That number is an upper bound that only applies when the column has more rows than possible values, so values repeat and nothing in the statistics says how many of the possible values occur. `estimate_semi_join_cardinality` used it as the inner side's NDV in `min(outer_ndv, inner_ndv) / outer_ndv`, which asserts that every value in the range occurs and that (almost) every outer key is covered. On TPC-H SF1, `customer NOT EXISTS orders` was estimated at 1 row against 50,004, and the anti join in Q22 at 0 rows against 6,384. `max_distinct_count` now reports where its count came from (measured, row count, value range, unknown), with unchanged numbers. The semi join path uses an explicit 0.5 overlap, PostgreSQL's `eqjoinsel_semi` default for a side without a measured distinct count, for an inner key whose count is range-derived. Measured and row-count-derived counts are used as before, so `orders EXISTS customer` and `orders EXISTS (filtered customer)` keep their estimates. Inner joins are untouched (apache#25618). Closes apache#25617
1 parent 0d79252 commit a53c4f4

2 files changed

Lines changed: 410 additions & 20 deletions

File tree

0 commit comments

Comments
 (0)