Skip to content

Make relation statistics traversal iterative - #122238

Open
cv4g wants to merge 3 commits into
masterfrom
relationstats-iterative-estimator
Open

cv4g wants to merge 3 commits into
masterfrom
relationstats-iterative-estimator

Conversation

@cv4g

@cv4g cv4g commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Extracted from #121736.

Refactor relation-statistics estimation to use an explicit stack instead of recursively traversing unary query-plan steps.

Changes:

  • Separate leaf relation estimation from unary-step statistics transformation.
  • Introduce classifyUnaryStepStats() and estimateUnaryStepStats().
  • Preserves existing behavior for limits, expressions, filters, aggregations, sorting, exchanges, and row-preserving transforms.
  • Keeps unsupported steps—including ARRAY JOIN, DistinctStep, FillingStep, and multi-input unions—as traversal boundaries without visiting their children.
  • Avoids stack growth for deeply nested unary plans.
  • Does not introduce relation-statistics caching or optimizer-wide signature changes.

Added focused tests covering iterative traversal and unsupported boundaries.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not for changelog.


Workflow [PR]
Sync PR [sync-upstream/pr/122238]

@clickhouse-gh

clickhouse-gh Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c56a307]

Summary: ✅


AI Review

Summary

PR #122238 replaces recursive relation-statistics traversal with an explicit stack and separates leaf estimation from unary statistics transformations. No actionable correctness or safety findings remain at c56a30754ae5dadd2b5e04a06205c0568ed6ae2f. The previous ArrayJoinStep finding is addressed.

Missing context / blind spots
  • ⚠️ Full builds and sanitizer unit-test jobs are pending in the CI report. Fast tests passed, but they do not execute the new RelationStatisticsEstimator unit tests. No local build or tests were run; completed unit-test results would close this validation gap.
Final Verdict

Status: ✅ Approve, subject to the normal required CI checks.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 25, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... label Sep 25, 2026
return UnaryStepStatsKind::Unsupported;
}

RelationStats estimateReadRowsCount(QueryPlan::Node & node, const ActionsDAG::Node * filter)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best viewed in split layout from here

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants