You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9e45962
Browse filesBrowse the repository at this point in the historyBrowse files
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
0 commit comments