englefly opened a new pull request, #70891: URL: https://github.com/apache/doris/pull/70891
### Background Nereids estimates an OLAP scan over pruned partitions from their row counts. A predicate proved true on those partitions can remain in the logical plan until physical post-processing so materialized-view matching can still see it. ### What problem does this PR solve? Issue Number: None Related PR: #63111 (deferred physical predicate removal) PR Type: Bugfix Problem Summary: The filter estimator applies the proven predicate to a row count that already describes the matching partitions. In the new LIST-partition regression, a scan estimated at 1,000 rows becomes a project estimated at 250 rows. Carry the pruning proof with the selected-partition estimate and charge selectivity only for residual filters. ### Details - **Frequency:** Always when a filter conjunct is proved true by pruning and still discounts a selected-partition estimate. - **Root cause:** StatsCalculator derives scan and filter statistics independently. The scan uses the surviving partitions, while the filter includes the same predicate in its selectivity calculation. - **Why existing tests missed it:** StatsCalculatorTest covered selected-partition scan statistics. The list_prune_predicate and prune_predicates_mv_test suites cover physical predicate removal and materialized views. They did not check the row count propagated past a filter over a pruned scan. - **Fix:** Keep the proof with the statistics derived from the matching partition set and subtract its exact conjuncts during estimation. Refine known keys for proved slot-to-literal equalities. This keeps the predicates available to materialized-view rewrite and leaves residual selectivity in FilterEstimation. - **Other paths and branches:** Logical and physical OLAP scans both use the fixed derivation. The deferred-predicate path from #63111 is also present in branch-4.0, branch-4.1, and branch-4.2. - **Behavior change:** The row count of a filter over a pruned scan now reflects the selected partitions and the residual filters. ### Testing - The partition_filter_selectivity suite checks the 1,000-row estimate, a 500-row residual estimate, and a filter on a multi-value partition. Local FE unit tests passed for StatsCalculatorTest. - The list_prune_predicate and prune_predicates_mv_test regression suites passed. - Regenerated 1,204 shape snapshots and verified 1,205 shape_check suites with the regression runner. The regenerated snapshots match the checked-in files. - 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 avoids underestimating rows when partition pruning already satisfies a filter predicate. ### 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]
