[opt](dphyper)optimize dphyper's statistics calculation (#64559) - #68204
Draft
starocean999 wants to merge 1 commit into
Draft
starocean999 wants to merge 1 commit into
starocean999 wants to merge 1 commit into
Conversation
Problem Summary:
After DPHyp join enumeration copies projected join alternatives into the
memo, the memo statistics are stale — DPHyp uses a lightweight heuristic
cost model that does not produce accurate row counts or column
distributions. Without a full statistics refresh, the subsequent
cascades optimization phase (OptimizeGroupJob) sees incorrect costs and
can produce suboptimal plans.
This PR introduces MemoStatsAndCostRecomputer, a bottom-up statistics
and cost recomputation pass that runs after DPHyp and before cascades
optimization. It re-estimates logical row counts for every memo group,
aggregates them according to a configurable policy, and rebuilds
physical costs from the refreshed statistics.
Key changes:
1. MemoStatsAndCostRecomputer (new)
- Bottom-up logical row-count re-estimation for every memo group.
- Trust-join-count aggregation policy: scores each candidate
expression by counting joins whose equal-join predicates have
high-confidence (ndv/rowCount > 0.9) column statistics, keeping
only the candidates with the most trusted joins.
- Per-group isStatsReliable tracking that stays consistent with the
selected/aggregated statistics instead of leaking from the last
candidate estimated in the loop.
- Project-group stats divergence protection: when two LogicalProject
alternatives diverge by >1000x in row count, the stats from the
currently-best PhysicalProject are preserved to avoid a misleading
aggregate (average/median).
- Two-pass logical re-estimation for CTE queries so consumers can
settle on refreshed producer stats.
- Physical-cost recomputation: clears and rebuilds per-group
lowest-cost-plan tables from the refreshed statistics.
2. countTrustJoins / getGroupTrustJoinCount
- Deterministic trust-join scoring: replaced child.getFirstLogical-
Expression() (memo-insertion-order dependent) with a per-group max
across all alternatives, memoized via groupTrustJoinCountCache.
- Cache is cleared before each logical re-estimation pass so CTE
producer stat changes are reflected.
3. hasTrustableEqualCondition (JoinEstimation)
- Rejects unknown column stats (ColumnStatistic.UNKNOWN) before the
NDV-ratio check. Unknown stats carry ndv=1, which could falsely
pass the >0.9 threshold on one-row tables.
4. GraphSimplifier cache isolation
- deriveStats and calCost now snapshot and restore their caches
between alternative join-order evaluations, preventing the second
alternative from reading column statistics derived for the first
alternative's join order.
5. DPHyp shape-check regression tests
- TPC-DS SF1000: 99 queries
- TPC-H SF1000: 22 queries
(cherry picked from commit 9e45962)
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pick #64559
What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)