englefly opened a new pull request, #70909: URL: https://github.com/apache/doris/pull/70909
### Background Nereids estimates the row count of an equijoin from statistics on its keys. For multiple keys it groups estimates by confidence and discounts additional predicates to account for possible correlation. ### What problem does this PR solve? Issue Number: None Related PR: #19046 (introduced the early fallback), #26086 (restored the max-row fallback) PR Type: Bugfix Problem Summary: A missing statistic for one equality sends the entire estimate directly to the max-input-row fallback. Two inputs estimated at 1,000 rows each with a known 10-value key and an unknown second key produce an estimate of 1,000 rows. Retaining the estimate from the known key gives 100,000 rows in the same fixture. ### Details - **Change map:** 144 lines of production code, 90 lines of tests, 209 lines of generated outputs. The estimator fix is covered by focused tests and regenerated snapshots. - **Frequency:** Always when mixed known and unknown equalities reach the inner estimate of an ordinary inner or outer join. - **Root cause:** JoinEstimation.estimateInnerJoin checked all equalities together before estimating any key. The early return also bypassed expansion and residual predicates when a known equality was available. - **Why existing tests missed it:** JoinEstimateTest covers join statistics with known keys. The invalid_stats_join_order regression exercises a different invalid-statistics policy. The new tests use known and unknown equijoin keys together and assert the mixed estimate directly. - **Fix:** Reuse the confidence and correlation estimation for usable equalities and give unknown equalities a neutral selectivity. Continue through expansion and residual estimation when a usable equality exists. Preserve the max-input-row fallback when all equalities are unknown. The generated TPC-DS snapshots change join order in Q44 and Q59, and build-side choice and runtime-filter placement in Q47 and Q57. - **Other paths and branches:** Logical and physical ordinary inner and outer joins share the changed estimator. Semi, anti and ASOF joins use specialized policies. The legacy fallback is present in branch-3.1, branch-4.0, branch-4.1 and branch-4.2. - **Behavior change:** Known equijoin keys continue to affect cardinality estimates when another key has missing statistics. ### Testing - The mixed_join_key_statistics regression fails at the join estimate on master and passes with this change. The new FE test also covers the all-unknown fallback, reversed key order, an outer join residual, and expansion. Local FE unit tests passed for JoinEstimateTest and StatsCalculatorTest. - Regenerated 1,204 shape snapshots and verified 1,205 shape_check suites with the regression runner. The generated diff updates 8 snapshots. - Built the FE with `build.sh --fe`. Local SQL regression used the Doris 4.1.5 BE with compatibility settings for data execution. ### Release note Nereids uses available key statistics for joins whose other keys have missing statistics. ### Check List (For Author) - Behavior changed: Yes (see Details) - Does this need documentation: No - Pre-submission status: Ready ### AI Disclosure - Tool: OpenAI Codex (GPT-6) - Generated: Code, tests, and PR description - Human review: Pending -- 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]
