Skip to content

Refactor: share the traversal of ActionsDAG nodes between its walks - #129671

Merged
murphy-4o merged 1 commit into
ClickHouse:masterfrom
murphy-4o:actions-dag-traversal-helpers
Nov 10, 2026
Merged

murphy-4o merged 1 commit into
ClickHouse:masterfrom
murphy-4o:actions-dag-traversal-helpers

Conversation

@murphy-4o

@murphy-4o murphy-4o commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Related: #129184

A refactor of the walks over ActionsDAG::Node::children. A node of an ActionsDAG can have several parents, and each walk re-implemented "visit every node once" by hand.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.1819-master (included in 26.11 and later)
  • Backported to: 26.10.7.23

Add `src/Interpreters/ActionsDAGTraversal.h`: `visitReachableNodes`,
`anyReachableNode`, `allReachableNodes`, `visitNodesPostOrder`,
`computeForNodes`, and `findReachableNodes` (moved from actionsDAGUtils
unchanged). Each visits a node at most once.

Rewrite the hand-written walks over `Node::children` in ActionsDAG.cpp,
FilterStep, filterPushDown, optimizeJoin and VirtualColumnUtils on top of them.
Results, output order, errors and hash values are unchanged. Walks that rewrite
children mid-walk, keep per-node state or depend on visit order stay as they are.
@clickhouse-gh

clickhouse-gh Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [63e4ffc]

Summary: ✅


AI Review

Summary

This PR consolidates traversal of ActionsDAG nodes into shared helpers, retaining child-first processing where required and avoiding repeated visits to shared nodes. Reviewed commit 63e4ffcb1fbe734361555e8f7c1e57ddfb41e95b; no actionable correctness, safety, or compatibility findings. The existing shared-node hashing, partial-evaluation, and constant-folding regressions passed in the fast-test report.

Missing context / blind spots
  • ⚠️ ASan, TSan, and MSan unit-test jobs were still queued at review time. Their completed reports are needed to confirm execution of the newly added traversal tests; no local build or tests were run.
Final Verdict

Status: ✅ Approve. No code changes requested; remaining CI should complete before merge.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Nov 6, 2026
@murphy-4o murphy-4o changed the title Share the traversal of ActionsDAG nodes between its walks Refactor: share the traversal of ActionsDAG nodes between its walks Nov 6, 2026
@murphy-4o
murphy-4o marked this pull request as ready for review November 6, 2026 04:56
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Nov 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 63e4ffcb1 with master b51445ef4 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

8 object files changed (-23.02 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Interpreters/ActionsDAG.cpp.o 1.45 MiB 1.43 MiB -27.24 KiB (-1.83%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

30 translation units recompiled, 252 s compile time in total, 30 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -16.9 s (-6%) in total before that adjustment.

Job report

@novikd novikd self-assigned this Nov 9, 2026

@novikd novikd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, but it would be nice to avoid traversing the same DAG several times

Comment thread src/Interpreters/ActionsDAG.cpp Resolved
@murphy-4o
murphy-4o added this pull request to the merge queue Nov 10, 2026
Merged via the queue into ClickHouse:master with commit f669d24 Nov 10, 2026
186 checks passed
@murphy-4o
murphy-4o deleted the actions-dag-traversal-helpers branch November 10, 2026 05:37
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 10, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 18, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Nov 19, 2026
Cherry pick #129671 to 26.10: Refactor: share the traversal of ActionsDAG nodes between its walks
robot-clickhouse added a commit that referenced this pull request Nov 19, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 19, 2026
murphy-4o added a commit that referenced this pull request Nov 19, 2026
The function is not on 26.10; #129671 only rewrote its body on master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clickhouse-gh Bot added a commit that referenced this pull request Nov 19, 2026
Backport #129671 to 26.10: Refactor: share the traversal of ActionsDAG nodes between its walks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants