Skip to content

Reintroduce explain analyze - #110668

Merged
Fgrtue merged 3 commits into
masterfrom
reintroduce-explain-analyze
Jul 16, 2026
Merged

Fgrtue merged 3 commits into
masterfrom
reintroduce-explain-analyze

Conversation

@Fgrtue

@Fgrtue Fgrtue commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #98117
Related: #106586
Related: #110162
Related: #110164

PR for EXPLAIN ANALYZE was reverted because of failed tests https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=ec064681ee99d6f2c0153607a0cb49bb190c30cc&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_msan%29 caused by Streaming Quries. #110164 fixed this problem. Current PR fully copies the fix.

Changelog category (leave one):

  • New Feature

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

  • Introduces EXPLAIN ANALYZE for ClickHouse.

Version info

  • Merged into: 26.7.1.1052 (included in 26.7 and later)

@clickhouse-gh

clickhouse-gh Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8f88118]

Summary: ✅


AI Review

Summary

This PR reintroduces EXPLAIN ANALYZE and wires runtime stats, quotas, and plan formatting through the executor. The main analyzer path is close, but I found one new blocker in the legacy (enable_analyzer = 0) streaming path, and one previously raised blocker still stands: result limits are still enforced on the emitted plan rows instead of only on the wrapped query. I would not merge this as-is.

Findings

❌ Blockers

  • [src/Interpreters/InterpreterExplainQuery.cpp:824] The new FROM ... STREAM rejection only runs when getAnalyzedInnerQuery has a query tree. With enable_analyzer = 0, EXPLAIN ANALYZE SELECT ... STREAM still goes through InterpreterSelectWithUnionQuery, reaches ReadFromMergeTree::groupPartitionsByStreams, and MergeTreeCommitOrderSequentialSource::updatePipeline injects a nested snapshot pipeline whose processors keep transient plan-step pointers from buildPartitionReadingPipeline. StepWallClockRegistry::populateFromPlan never registers those steps, so the restored chassert(clock) in src/Processors/Executors/ExecutionThreadContext.cpp still fires in debug/ASan builds; in release builds the query no longer asserts but hangs forever because the streaming read never completes.
    Suggested fix: reject streaming reads on the legacy path too (for example by checking AST/table-expression modifiers around the InterpreterSelectWithUnionQuery branch), or retag the injected snapshot processors to an outer step before returning them from MergeTreeCommitOrderSequentialSource::updatePipeline.
  • [src/Interpreters/InterpreterExplainQuery.cpp:1209-1217, src/Interpreters/executeQuery.cpp:1986-1987] [dismissed by author -- https://github.com/Reintroduce explain analyze #110668#discussion_r3594918935] EXPLAIN ANALYZE now applies setLimitsAndQuota to the wrapped query's execution pipeline and then executeQueryImpl applies the same result/execution limits again to the one-column EXPLAIN output. That breaks the advertised "behaves like the wrapped query" contract: EXPLAIN ANALYZE SELECT number FROM numbers(1) SETTINGS max_result_rows = 1 should succeed, but the outer wrapper still throws once the plan output exceeds one row.
    Suggested fix: plumb a way for InterpreterExplainQuery / BlockIO to tell executeQueryImpl that result limits/quota were already attached to the inner execution pipeline, and skip the outer pipeline.setLimitsAndQuota for executable EXPLAIN ANALYZE.
Final Verdict

❌ Not ready to merge: the legacy streaming path is still broken, and EXPLAIN ANALYZE still enforces result limits on the printed plan instead of only on the wrapped query.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jul 16, 2026
@mintlify

mintlify Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Jul 16, 2026, 11:13 AM

@Fgrtue

Fgrtue commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

The work was reviewed: first in #106586 and in #110164. The current implementation does not essentially differ from #106586 and almost fully (up to documentation) repeats #110164. That is why no additional review by a human reviewer is needed.

out << "\n";
}

static void rejectStreamingForExplainAnalyze(const QueryTreeNodePtr & query_tree)

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.

@Michicosun would that be an accurate and full check for rejecting streaming queries in EXPLAIN ANALYZE?

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.

Yes, looks great!

Comment thread src/Interpreters/executeQuery.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.90% 85.90% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 78.00% 78.00% +0.00%

Changed lines: Changed C/C++ lines covered: 765/851 (89.89%) · Uncovered code

Full report · Diff report

@Fgrtue
Fgrtue added this pull request to the merge queue Jul 16, 2026
Merged via the queue into master with commit 1765194 Jul 16, 2026
178 checks passed
@Fgrtue
Fgrtue deleted the reintroduce-explain-analyze branch July 16, 2026 20:53
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 16, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product 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