pub fn estimate_join_rows_multi(
left_rows: u64,
right_rows: u64,
key_domains: &[(Option<u64>, Option<u64>)],
) -> u64Expand description
Multi-key equijoin intermediate cardinality:
|L| · |R| / Π_v max(dom_L(v), dom_R(v)) over the join keys, assuming
key independence.
Per key, the divisor factor is the KNOWN side’s domain, capped by its
own side’s row count (distinct values never exceed own rows). When one
side’s domain is unknown (missing HLL, Path, SubSelect boundary)
the known side alone is used: the structural bound dom ≤ own rows
means a known domain already at/above the other side’s rows pins
max(...) exactly, and below that the known domain is the smallest
plausible max — both over-estimate relative to the uniform assumption,
the safe direction for advisory stats. A key unknown on both sides
contributes no factor; when no key carries any domain the Phase 7
min(|L|, |R|) heuristic stands. Both-sides-ground-unique keys need
no special case (their factor is 1 — multiplying by 1 is identity,
unlike the min-aggregation in the planner’s allow-list channel, which
must exclude no-op keys so a domain-1 key cannot drag the minimum
down).
Independence is the known hazard: correlated keys (e.g. one functionally determined by the other in the data) over-divide and under-estimate within this formula; estimates stay advisory-only.