Skip to content

Stateless Workers EXPLAIN PLAN tree = 1: one box per step, a frame per query fragment, exchanges as edges between the send and receive steps - #126706

Merged
diegomestre2 merged 17 commits into
ClickHouse:masterfrom
diegomestre2:explain_tree
Nov 3, 2026
Merged

diegomestre2 merged 17 commits into
ClickHouse:masterfrom
diegomestre2:explain_tree

Conversation

@diegomestre2

@diegomestre2 diegomestre2 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Related: #124179
Related: #124600
Related: #124893

Part of the fragment-aware EXPLAIN series described in the RFC above.

Changes

  • New EXPLAIN PLAN option tree = 1. After optimization, a plan that stays distributed is cut and turned into a FragmentGraph exactly as for fragments = 1, and rendered by the new explainFragmentGraphTree:
    • one box per step, connected as in the plan tree, and a frame around the steps of each query fragment, titled F<id> · <stage name>;
    • every fragment is drawn under the fragment that reads it, in rows by its distance from the fragment that produces the result;
    • every exchange is an edge from the producer's send step up to the consumer's receive step.
  • The layout is one tidy tree over all steps, with the receive step of a fragment as the parent of the producer's send step.
  • The drawing is monochrome UTF-8 at its natural width, rendered on the server: it does not depend on the terminal.
  • A box shows the step name and, with description = 1, its description; pretty drops the table prefix of column names; estimates = 1 adds the estimated rows to the labels.
  • A plan that is not distributed (or fell back to local execution) prints the usual plan
  • New TextCanvas, a small grid of cells with box drawing and wide-character support (UTF8::computeWidth), reusable by later text views (the planned timeline).

Example, a join with an aggregation:

EXPLAIN tree = 1
SELECT small.sid, count()
FROM big, small
WHERE small.sid = (big.bid + 1) % 5000
GROUP BY small.sid
SETTINGS make_distributed_plan = 1, distributed_plan_max_rows_to_broadcast = 0;
                                                ┌─ F4 · main ────────────────────┐
                                                │                                │
                                                │  ┌───────────────────────────┐ │
                                                │  │ GatherSend (final_result) │ │
                                                │  └─────────────▲─────────────┘ │
                                                │                │               │
                                                │ ┌──────────────┴─────────────┐ │
                                                │ │ GatherReceive (exchange_3) │ │
                                                │ └──────────────▲─────────────┘ │
                                                └────────────────┼───────────────┘
                                                                 │ exchange_3 · gather
                                                                 │ streaming · 8 → 1
                                         ┌─ F3 · stage_3 ────────┼──────────────────────┐
                                         │                       │                      │
                                         │          ┌────────────┴────────────┐         │
                                         │          │ GatherSend (exchange_3) │         │
                                         │          └────────────▲────────────┘         │
                                         │                       │                      │
                                         │ ┌─────────────────────┴────────────────────┐ │
                                         │ │ Expression ((Project names + Projection… │ │
                                         │ └─────────────────────▲────────────────────┘ │
                                         │                       │                      │
                                         │                ┌──────┴──────┐               │
                                         │                │ Aggregating │               │
                                         │                └──────▲──────┘               │
                                         │                       │                      │
                                         │        ┌──────────────┴──────────────┐       │
                                         │        │ ShuffleReceive (exchange_2) │       │
                                         │        └──────────────▲──────────────┘       │
                                         └───────────────────────┼──────────────────────┘
                                                                 │ exchange_2 · hash(sid)
                                                                 │ streaming · 8 → 8
       ┌─ F2 · stage_2 ──────────────────────────────────────────┼─────────────────────────────────────────────────────────┐
       │                                                         │                                                         │
       │                                           ┌─────────────┴────────────┐                                            │
       │                                           │ ShuffleSend (exchange_2) │                                            │
       │                                           └─────────────▲────────────┘                                            │
       │                                                         │                                                         │
       │                                         ┌───────────────┴──────────────┐                                          │
       │                                         │ Expression (Before GROUP BY) │                                          │
       │                                         └───────────────▲──────────────┘                                          │
       │                                                         │                                                         │
       │                                                  ┌──────┴──────┐                                                  │
       │                                                  │ JoinLogical │                                                  │
       │                                                  └──────▲──────┘                                                  │
       │                                                         │                                                         │
       │                ┌────────────────────────────────────────┴────────────────────────────────────────┐                │
       │ ┌──────────────┴──────────────┐                                                   ┌──────────────┴──────────────┐ │
       │ │ ShuffleReceive (exchange_0) │                                                   │ ShuffleReceive (exchange_1) │ │
       │ └──────────────▲──────────────┘                                                   └──────────────▲──────────────┘ │
       └────────────────┼─────────────────────────────────────────────────────────────────────────────────┼────────────────┘
                        │ exchange_0 · hash(modulo(plus(bid, 1_UInt8), 50…                                │ exchange_1 · hash(sid)
                        │ streaming · 8 → 8                                                               │ streaming · 8 → 8
┌─ F0 · stage_0 ────────┼──────────────────────┐                                  ┌─ F1 · stage_1 ────────┼──────────────────────┐
│                       │                      │                                  │                       │                      │
│         ┌─────────────┴────────────┐         │                                  │         ┌─────────────┴────────────┐         │
│         │ ShuffleSend (exchange_0) │         │                                  │         │ ShuffleSend (exchange_1) │         │
│         └─────────────▲────────────┘         │                                  │         └─────────────▲────────────┘         │
│                       │                      │                                  │                       │                      │
│ ┌─────────────────────┴────────────────────┐ │                                  │ ┌─────────────────────┴────────────────────┐ │
│ │ Filter (((Apply runtime join filter + C… │ │                                  │ │ BuildRuntimeFilter (Build runtime join … │ │
│ └─────────────────────▲────────────────────┘ │                                  │ └─────────────────────▲────────────────────┘ │
│                       │                      │                                  │                       │                      │
│      ┌────────────────┴────────────────┐     │                                  │ ┌─────────────────────┴────────────────────┐ │
│      │ ReadFromMergeTree (default.big) │     │                                  │ │ Expression (Change column names to colu… │ │
│      └─────────────────────────────────┘     │                                  │ └─────────────────────▲────────────────────┘ │
└──────────────────────────────────────────────┘                                  │                       │                      │
                                                                                  │     ┌─────────────────┴─────────────────┐    │
                                                                                  │     │ ReadFromMergeTree (default.small) │    │
                                                                                  │     └───────────────────────────────────┘    │
                                                                                  └──────────────────────────────────────────────┘

Exchanges:
  exchange_0: hash(modulo(plus(bid, 1_UInt8), 5000_UInt16)), streaming, F0 -> F2, buckets 8 -> 8
  exchange_1: hash(sid), streaming, F1 -> F2, buckets 8 -> 8
  exchange_2: hash(sid), streaming, F2 -> F3, buckets 8 -> 8
  exchange_3: gather, streaming, F3 -> F4, buckets 8 -> 1
Levels: [F0, F1] -> [F2] -> [F3] -> [F4]

Changelog category (leave one):

  • Experimental Feature

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

Added EXPLAIN PLAN tree = 1, which draws a plan executed by stateless workers (make_distributed_plan = 1) as boxes, one per step, framed by query fragment and connected by the exchanges between the fragments, followed by the list of exchanges and the levels of the fragments.


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

Version info

  • Merged into: 26.11.1.1258-master (included in 26.11 and later)

@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [be5b5e8]

Summary: ✅


AI Review

Summary

Adds EXPLAIN PLAN tree = 1 to draw stateless-worker plan steps inside fragment frames, connected by labelled exchanges, and shares exchange formatting with fragments = 1. Reviewed revision be5b5e87fe049edbef861032ed5ad317a1872e46 and all prior discussion. No actionable findings remain; the previously reported loss of zero-width Unicode characters is fixed and has regression coverage.

Missing context / blind spots
  • ⚠️ Current-head functional CI was still pending, and no local ClickHouse build was available to rerun the stateless tests. Completed current-head functional results would close this runtime-validation gap.
Final Verdict

Status: ✅ Approve. No additional code changes requested; normal CI completion remains necessary.

@clickhouse-gh clickhouse-gh Bot added the comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... label Oct 19, 2026
@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Oct 19, 2026
@diegomestre2 diegomestre2 changed the title Explain tree EXPLAIN PLAN tree = 1: one box per step, a frame per query fragment, exchanges as edges between the send and receive steps Oct 19, 2026
@diegomestre2 diegomestre2 added the can be tested Allows running workflows for external contributors label Nov 2, 2026
@diegomestre2
diegomestre2 marked this pull request as ready for review November 2, 2026 12:12
@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing be5b5e87f with master 3b3f22da1 (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

46 object files changed (+226.95 KiB total), 3 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Fragments/PreparedFragmentGraph.cpp.o new 150.54 KiB +150.54 KiB
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Fragments/FragmentGraphTree.cpp.o new 145.04 KiB +145.04 KiB
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Fragments/FragmentGraphExplain.cpp.o 154.26 KiB 21.18 KiB -133.08 KiB (-86.27%)
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Fragments/TextCanvas.cpp.o new 40.83 KiB +40.83 KiB
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ParserExplainQuery.cpp.o 171.09 KiB 192.31 KiB +21.22 KiB (+12.40%)

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

284 translation units recompiled, 2376 s compile time in total, 281 of them have a recent master baseline.

Job report

@diegomestre2 diegomestre2 changed the title EXPLAIN PLAN tree = 1: one box per step, a frame per query fragment, exchanges as edges between the send and receive steps Stateless Workers EXPLAIN PLAN tree = 1: one box per step, a frame per query fragment, exchanges as edges between the send and receive steps Nov 3, 2026

@antoniofilipovic antoniofilipovic 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.

Looks good for now, let me know what do you think about this first batch of comments.

Comment thread src/Parsers/ParserExplainQuery.cpp Resolved
@diegomestre2

Copy link
Copy Markdown
Contributor Author

Thanks very much for all the comments, @antoniofilipovic ! I addressed the requests and made some improvements to comments and UI. Let me know what you think.

@antoniofilipovic antoniofilipovic 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!

@diegomestre2
diegomestre2 added this pull request to the merge queue Nov 3, 2026
Merged via the queue into ClickHouse:master with commit 3ad8cb6 Nov 3, 2026
185 checks passed
@diegomestre2
diegomestre2 deleted the explain_tree branch November 3, 2026 21:37
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 3, 2026
@clickhouse-gh clickhouse-gh Bot added comp-explain EXPLAIN and query profiling output: EXPLAIN PLAN / PIPELINE / AST / SYNTAX / ESTIMATE, pretty EXP... and removed comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-explain EXPLAIN and query profiling output: EXPLAIN PLAN / PIPELINE / AST / SYNTAX / ESTIMATE, pretty EXP... pr-experimental Experimental Feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants