Skip to content

Explain analyze works for Streaming queries - #112445

Merged
Fgrtue merged 6 commits into
masterfrom
explain-analyze-streaming-queries
Aug 11, 2026
Merged

Fgrtue merged 6 commits into
masterfrom
explain-analyze-streaming-queries

Conversation

@Fgrtue

@Fgrtue Fgrtue commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Closes: #112328

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

@Fgrtue Fgrtue changed the title Explain analyze streaming queries Explain analyze works for Streaming queries Jul 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ba22518]

Summary: ✅


AI Review

Summary

This PR removes the EXPLAIN ANALYZE rejection for FROM ... STREAM queries and retags runtime-expanded streaming sub-pipelines so their work is attributed to a visible plan step. The plain MergeTree path looks covered, but the lazy-FINAL streaming path is still unsafe: the new retagging collapses an inner two-stage aggregation onto the outer ReadFromMergeTree step, and the second stage can still miss the wall-clock registry entry that EXPLAIN ANALYZE requires. This still needs a fix before merge.

Findings

❌ Blockers

  • [dismissed by author -- https://github.com/Explain analyze works for Streaming queries #112445#discussion_r3675534740] [src/Storages/MergeTree/Streaming/MergeTreeCommitOrderSequentialSource.cpp:501-503] buildNextSnapshotReadingPipeline keeps the original SelectQueryInfo and then runs unified.optimize(opt_settings), so a snapshot for ReplacingMergeTree ... FINAL STREAM can still be rewritten to LazyReadReplacingFinalStep. The new loop here rewrites every detached processor in that transient snapshot pipeline to the outer ReadFromMergeTree step/group 0. That is fine for the first wave, but the embedded AggregatingTransform in the lazy-FINAL plan later generates its merge wave in getGeneratingStepGroup() as group 1 (src/Processors/Transforms/AggregatingTransform.cpp:1052-1165), and LazyReadReplacingFinalStep explicitly relies on that split (src/Processors/QueryPlan/LazyReadReplacingFinalStep.cpp:19-27). StepWallClockRegistry only creates clocks for step/group pairs present in the main plan (src/Processors/StepWallClockRegistry.cpp:18-47); ReadFromMergeTree contributes only the default group 0, so when that generated merge wave executes, ExecutionThreadContext::executeTask still finds no clock for (ReadFromMergeTree, 1) and hits chassert(clock) in debug/ASan builds (src/Processors/Executors/ExecutionThreadContext.cpp:99-113). A focused regression on EXPLAIN ANALYZE SELECT ... FINAL STREAM ... LIMIT ... over ReplacingMergeTree should fail today and would pin the fix.
Final Verdict

❌ Changes required before merge.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.60% 86.60% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.80% 78.90% +0.10%

Changed lines: Changed C/C++ lines covered: 25/25 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 29, 2026
inputs.emplace_back(pipeline_output->getHeader(), this);
connect(*pipeline_output, inputs.back());
inputs.back().setNeeded();
shareQueryPlanStepWithSubPipeline(processors, getQueryPlanStepGroup());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shareQueryPlanStepWithSubPipeline fixes the LazyReadReplacingFinalSource arm, but the lazy-FINAL plan still has a second runtime-expanded arm that is left untouched: LazilyUnorderedReadFromMergeTreeSource::updatePipeline detaches processors built from a stack-allocated ReadFromMergeTree step in buildPipe() and never re-parents them.

That branch is still reachable from the newly-enabled streaming path: MergeTreeCommitOrderSequentialSource::buildPartitionReadingPipeline preserves the original SelectQueryInfo, plan.optimize() can apply optimizeLazyFinal, and the true branch there creates LazilyUnorderedReadFromMergeTree. For a query like EXPLAIN ANALYZE SELECT ... FINAL STREAM WHERE ... LIMIT ... on ReplacingMergeTree, those processors keep a step pointer the wall-clock registry never populated, so ExecutionThreadContext::executeTask still hits chassert(clock) in debug/ASan builds (and release silently drops the timing for that branch).

Please tag that sub-pipeline as well, or clear its transient step pointers so the executor can inherit the parent step before we consider streaming EXPLAIN ANALYZE fixed.

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.

The idea of this patch is not to retag the processors using this new function in every place. We do this only in processors that create their own plan inside, and thus their processors can get tagged with the steps from this plan. Thus, the steps assigned to those processors (created from internal local plan) get non-null step, which then causes chassert firing in EXPLAIN ANALYZE, cause we cannot find clocks for those steps.

For the case of LazyUnorderedReadFromMergeTreeSource::updatePipeline there is no such problem. We create processors in ReadFromMergeTree::initializePipeline, and this function creates processors with nullptr steps, which then get their step assigned in ExecutingGraph::updatePipeline.

@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.60% 78.70% +0.10%

Changed lines: Changed C/C++ lines covered: 27/29 (93.10%) · Uncovered code

Full report · Diff report

@Michicosun Michicosun self-assigned this Jul 31, 2026
Comment thread src/Processors/IProcessor.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ba22518ec with master e252b7822 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of ccd0884b7; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 690.65 MiB 687.64 MiB -3.01 MiB (-0.44%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

@Fgrtue
Fgrtue added this pull request to the merge queue Aug 11, 2026
Merged via the queue into master with commit 639756d Aug 11, 2026
181 checks passed
@Fgrtue
Fgrtue deleted the explain-analyze-streaming-queries branch August 11, 2026 14:46
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 11, 2026
alexey-milovidov added a commit that referenced this pull request Aug 24, 2026
Edited following .claude/skills/edit-changelog/SKILL.md, by hand on a
workstation: the editing step of the NightlyChangelog job has been failing
its own verification since 2026-08-12, so three raw blocks had accumulated
(47 + 84 + 628 entries).

Of the 759 raw entries, 482 are integrated into the in-progress 26.8 section
and 277 are dropped:

- Section 3: the 300 `NOT FOR CHANGELOG / INSIGNIFICANT` entries are dropped,
  except 41 that describe a user-visible change and are promoted into a real
  category, among them a server abort on a corrupt `ORC` stripe footer
  (#114924), `EXPLAIN ANALYZE` for streaming queries (#112445), `SELECT` from
  `TimeSeries` (#115622), streaming watermarks (#106169), and the
  `clickhouse-local` CORS overrides (#115129).
- Section 2: every revert in the range cancels out inside it, so neither side
  appears. Two are re-applications: #114912 re-applies the
  `accurateCastOrDefault` fix, so #109946 keeps its entry with both links and
  the intervening revert #114911 is gone; #114409 re-applies the PromQL
  streaming plan, recorded on the #113656 entry.
- Section 4: `Build/Testing/Packaging Improvement` keeps the seven entries a
  user, packager or from-source builder notices (musl `getaddrinfo` and
  `sched_getcpu`, signed macOS artifacts, Debian packages for release builds
  only, zstd-compressed Docker layers, `unit_tests_dbms` without the full
  library set, vendored Rust built with optimizations locally) and drops the
  CI plumbing.
- Sections 5 and 6: bare pull request URLs converted to links, settings put
  in backticks, four entries rewritten from developer notes into user-visible
  descriptions, and three moved into `Performance Improvement`.

No entry of a strict-retention category was deleted: the job's own
`verify_edit` passes on this edit.

Not done here, because the release manager does it at release time: the full
significance sort, the aggressive merging of sibling pull requests, and the
`FIXME` release date and presentation links.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explain analyse support Streaming Queries

3 participants