Skip to content

Revert "Explain analyze" (#106586) - #110162

Merged
alexey-milovidov merged 2 commits into
masterfrom
revert-explain-analyze
Jul 12, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
revert-explain-analyze

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

Reverts the EXPLAIN ANALYZE feature added in #106586.

This is a git revert -m 1 of the merge commit 918a0d32a0cab22b2eb17c5d151c1245650465ef. It removes the query-executor instrumentation (StepWallClock, StepWallClockRegistry, AnalyzePlanStats, per-step wall-clock and per-port data accounting on IProcessor, per-stage processor grouping on SortingStep/AggregatingStep/JoinStep), the ANALYZE keyword and its handling in ParserExplainQuery/InterpreterExplainQuery, StreamLocalLimits::forQueryResult, and the associated tests and documentation.

There are no merged follow-up pull requests to revert. The only follow-up, #110077 ("Reject EXPLAIN ANALYZE for streaming (STREAM) queries"), is still open and not part of master; it depends on this feature and would need to be closed or reworked.

The single revert conflict, in tests/queries/0_stateless/03269_explain_unique_ids.reference, was resolved to keep the unrelated node-id renumbering later introduced by "Fix Not-ready Set exception by making in-place set build non-destructive" (5583c9a4176) while reverting only the EXPLAIN ANALYZE step-id change.

Related: #106586
Related: #110077

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):

Revert of #106586 (EXPLAIN ANALYZE). The feature was added in the current development cycle and has not appeared in a stable release, so no user-facing changelog entry is required.

Documentation entry for user-facing changes

  • Not applicable — this revert removes the feature and its documentation.

Version info

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

This reverts the `EXPLAIN ANALYZE` feature added in
#106586 (merge commit
918a0d3), a revert of that merge with `-m 1`.

It removes the query-executor instrumentation (`StepWallClock`,
`StepWallClockRegistry`, `AnalyzePlanStats`, per-step wall-clock and per-port
data accounting on `IProcessor`, per-stage processor grouping on
`SortingStep`/`AggregatingStep`/`JoinStep`), the `ANALYZE` keyword and its
handling in `ParserExplainQuery`/`InterpreterExplainQuery`,
`StreamLocalLimits::forQueryResult`, and the associated tests and
documentation.

There are no merged follow-up pull requests to revert. The only follow-up,
#110077 ("Reject EXPLAIN ANALYZE
for streaming (STREAM) queries"), is still open and not part of `master`.

The single revert conflict, in
`tests/queries/0_stateless/03269_explain_unique_ids.reference`, was resolved to
keep the unrelated node-id renumbering introduced later by "Fix Not-ready Set
exception by making in-place set build non-destructive" (5583c9a) while
reverting only the `EXPLAIN ANALYZE` step-id change.

Co-Authored-By: Claude Fable 5 <[email protected]>
@mintlify

mintlify Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

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

Project Status Preview Updated (UTC)
ClickHouse-docs 🟡 Building – Jul 12, 2026, 3:49 PM

@clickhouse-gh

clickhouse-gh Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cdb1ed9]


AI Review

Summary

This PR reverts EXPLAIN ANALYZE and the related executor instrumentation, but the revert is not clean on the current master codebase. It also removes generic processor-to-step tagging that other existing EXPLAIN PIPELINE paths still depend on, introduces an invalid downcast in pretty EXPLAIN formatting for aggregate projections, and keeps the runtime-processor attribution regression that was already discussed on the PR.

Findings

❌ Blockers

  • [src/Processors/QueryPlan/QueryPlanFormat.cpp:615] AggregatingProjectionStep is no longer handled as its own type during pretty-name formatting. The new static_cast<const AggregatingStep *>(step.get()) is invalid when step_name == "AggregatingProjection", so default-pretty EXPLAIN on queries that use aggregate projections now has undefined behavior and can produce garbage output or hit an exception. Suggested fix: restore a dedicated AggregatingProjectionStep branch and read params from that class, or restore AggregatingProjectionStep::getParams.

⚠️ Majors

  • [src/Processors/QueryPlan/QueryPlan.cpp:257] Removing the generic fallback that assigns QueryPlanStep to untagged processors regresses existing explain paths outside ANALYZE. Steps such as ReadFromRemote and the exchange send steps still build processors without a collector/manual tag, so EXPLAIN PIPELINE graph=1 now loses step clusters entirely; the changed tests/queries/0_stateless/03213_distributed_analyzer.reference already shows the ReadFromRemote cluster disappearing. Suggested fix: keep this fallback, or explicitly tag/collect processors in every affected step before returning the pipeline.
  • [src/QueryPipeline/QueryPipelineBuilder.cpp:574] joinPipelinesRightLeft no longer adds the left-side SimpleSquashingChunksTransform processors to collected_processors. They still execute, but they drop out of JoinStep::processors, so textual EXPLAIN PIPELINE silently omits that squashing wave when min_block_size_rows or min_block_size_bytes is enabled. Suggested fix: add the same if (collected_processors) collected_processors->emplace_back(squashing); handling that the surrounding processors still get.
  • [src/Processors/Executors/ExecutingGraph.cpp:185] [dismissed by author -- https://github.com/Revert "Explain analyze" (#106586) #110162#discussion_r3566660594] Runtime-created processors still lose their parent step attribution after this revert. The current 03269_explain_unique_ids.reference shows ConvertingAggregatedToChunksTransform with an empty step_uniq_id, which regresses system.processors_profile_log and any tooling that correlates processor samples back to plan steps. I still consider this real because it affects current master observability outside the deleted EXPLAIN ANALYZE entrypoint.
Final Verdict

Status: ⚠️ Request changes
Minimum required actions: fix the AggregatingProjectionStep downcast in pretty EXPLAIN, restore processor-step tagging/collection for the existing EXPLAIN PIPELINE paths that now lost it, and address the remaining runtime-processor attribution regression or explicitly carve it out into a follow-up instead of silently regressing it here.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 12, 2026
@alexey-milovidov alexey-milovidov self-assigned this Jul 12, 2026

/// Record new processors in pipeline
const IProcessor & parent = *cur_node.processor();
for (const auto & new_proc : update.to_add)

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.

This drops the only generic place that re-attaches runtime-created processors to a query-plan step. After this, any updatePipeline implementation that returns fresh processors without manually tagging them, such as AggregatingTransform, MergeSortingTransform, LazyReadReplacingFinalSource, LazyReadFromMergeTreeSource, or DelayedSource, will log them with empty step_uniq_id / plan_step_name. The updated 03269_explain_unique_ids.reference already shows ConvertingAggregatedToChunksTransform losing its Aggregating_4 association. That is a regression for system.processors_profile_log and any tooling that correlates processors back to plan steps. Please either keep the generic inheritance here or re-tag every runtime-added processor before addNode.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is intentional: the PR is a clean git revert -m 1 of #106586, and this attribution block was added by that same feature (commit 1f966c9e65c "Propagate parent processor step to the newly created processor", which lives on the explain-analyze branch, not on master before the merge). Reverting it restores the exact pre-#106586 behavior — on master before the merge, system.processors_profile_log already reported ConvertingAggregatedToChunksTransform (and other runtime-added processors) with an empty step_uniq_id, as the reverted 03269_explain_unique_ids.reference line confirms. The feature never shipped in a stable release, so this is not a regression relative to any released version.

Preserving just the runtime-processor step propagation as a standalone improvement would turn this into a partial revert (it also depends on getQueryPlanStepGroup / inheritQueryPlanStepFromParent, which this revert removes). Leaving that decision to @alexey-milovidov as the author — happy to split it into a small follow-up on master if we want to keep that system.processors_profile_log attribution.

…list

The revert of #106586 removed the `ANALYZE`, `ESTIMATE`, and `TABLE OVERRIDE`
bullets from the `EXPLAIN Types` overview list, but `ESTIMATE` and
`TABLE OVERRIDE` are still advertised in the syntax block and still have their
own `### EXPLAIN ESTIMATE` and `### EXPLAIN TABLE OVERRIDE` sections later in
the same document. Re-add those two bullets (but not `ANALYZE`, which is
removed by this revert) so the page is internally consistent again.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@@ -259,10 +257,6 @@ QueryPipelineBuilderPtr QueryPlan::buildQueryPipeline(
if (limit_max_threads && max_threads)

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.

This removes the last generic backstop that tags processors returned by a step. Several existing steps still rely on it because they create processors without a collector or manual setQueryPlanStep, for example ReadFromRemote::initializePipeline and the exchange send steps. The updated 03213_distributed_analyzer.reference already shows the effect: EXPLAIN PIPELINE graph=1 loses the ReadFromRemote cluster entirely because every processor in that subgraph now has step == nullptr. Please keep the fallback here or teach those steps to tag/collect their processors explicitly.

pretty_names[output->result_name] = PrettyColumnName(formatNodePretty(output, pretty_names, runtime_filter_names, subquery_set_names));
}
else if (step_name == "Aggregating")
else if (step_name == "Aggregating" || step_name == "AggregatingProjection")

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.

AggregatingProjectionStep is not derived from AggregatingStep, so this merged branch turns pretty-name formatting into UB for plans that contain an aggregate projection. When step_name == "AggregatingProjection", the static_cast<const AggregatingStep *>(step.get()) reads the wrong object layout, so default-pretty EXPLAIN can emit garbage or hit an exception. Please keep a separate AggregatingProjectionStep branch here, or restore a getParams accessor on that class and use the right cast.

connect(*left_port, squashing->getInputs().front());
left_port = &squashing->getOutputPort();
add_to_left_pipe(std::move(squashing));
left->pipe.processors->emplace_back(std::move(squashing));

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.

The old add_to_left_pipe helper appended new processors both to left->pipe.processors and to collected_processors. After inlining it, this left-side SimpleSquashingChunksTransform only goes into the pipe itself, so JoinStep::processors no longer sees it. Textual EXPLAIN PIPELINE will silently omit that squashing wave whenever min_block_size_rows or min_block_size_bytes is enabled, and with the generic tagging fallback above removed it also stays untagged for graph/profile output. This needs the same if (collected_processors) collected_processors->emplace_back(squashing); treatment as the other processors in this function.

@alexey-milovidov
alexey-milovidov merged commit 178267d into master Jul 12, 2026
11 of 14 checks passed
@alexey-milovidov
alexey-milovidov deleted the revert-explain-analyze branch July 12, 2026 17:24
alexey-milovidov added a commit that referenced this pull request Jul 12, 2026
Reintroduces the `EXPLAIN ANALYZE` feature (originally #106586) by reverting
its revert #110162 (merge commit 178267d, reverted with `-m 1`).

The feature was reverted only because of a `Logical error: 'clock'` abort in
`EXPLAIN ANALYZE` over a streaming (`FROM ... STREAM`) read in debug and
sanitizer builds. The following commit fixes that bug, so the feature can be
reintroduced.

This restores the query-executor instrumentation (`StepWallClock`,
`StepWallClockRegistry`, `AnalyzePlanStats`, per-step wall-clock and per-port
data accounting on `IProcessor`, per-stage processor grouping on
`SortingStep`/`AggregatingStep`/`JoinStep`), the `ANALYZE` keyword and its
handling in `ParserExplainQuery`/`InterpreterExplainQuery`,
`StreamLocalLimits::forQueryResult`, and the associated tests and documentation.

Related: #106586
Related: #110162

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 12, 2026
alexey-milovidov added a commit that referenced this pull request Jul 12, 2026
alexey-milovidov added a commit that referenced this pull request Jul 13, 2026
Pull in the revert of `EXPLAIN ANALYZE` (#110162, merged after this
branch's previous merge-base) which removes the `InterpreterExplainQuery`
`'clock'` logical error at `InterpreterExplainQuery.cpp:1234`. That error
was the cause of the unrelated `Stress test (arm_tsan)` AST-fuzzer
failure on this PR (stack: executeASTFuzzerQueries -> InterpreterExplainQuery::executeImpl,
zero HiveText/serialization frames). Also brings the branch up to date
with the current master.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alexey-milovidov added a commit to filimonov/ClickHouse that referenced this pull request Aug 2, 2026
… was reintroduced

`EXPLAIN ANALYZE` was reverted from master in ClickHouse#110162 and reintroduced in ClickHouse#110164,
so the merge brings back `InterpreterExplainQuery.cpp`, which builds its accounting
group with `std::make_shared<ThreadGroup>(outer_thread_group)`. This branch makes the
borrowing `ThreadGroup` constructor private so borrowed groups are created only through
factories, so the merge does not compile: `calling a private constructor of class
'DB::ThreadGroup'`.

Re-add the `createForExplainAnalyze` factory (matching `createForMaterializedView` and
`createForFlushAsyncInsertQueue`) and use it at the call site. This is the same change as
9b8462b, which was dropped by the previous merge because master had `EXPLAIN ANALYZE`
reverted at the time.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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-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.

2 participants