Fix Block structure mismatch exception in UnionStep with PREWHERE and projections#99515
Merged
alexey-milovidov merged 3 commits intomasterfrom Mar 23, 2026
Merged
Conversation
…nd projections Move the debug assertion in `UnionStep::updatePipeline` after the header conversion code. Previously, the assertion fired before the existing converting transform could fix the mismatch, causing a fatal error in debug/sanitizer builds. The mismatch occurs when PREWHERE optimization adds extra pass-through columns to `ReadFromMergeTree` output via `ActionsDAG::updateHeader` that are not consumed by the expression DAG above. This causes plan headers and actual pipeline headers to diverge. The conversion code already handles this gracefully by adding converting transforms, but the assertion prevented it from running in debug builds. Fixes #96131 https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=73f45b0717e3a4763b7d1cde71950a076b5b00c7&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_msan%29 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Workflow [PR], commit [21e09b2] Summary: ✅ AI ReviewSummaryThis PR fixes a debug/ASan-only ClickHouse Rules
Final Verdict
|
…WHERE and projections This test exercises the PREWHERE + projection + `query_plan_remove_unused_columns = 0` path that caused a debug assertion failure in `UnionStep::updatePipeline`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 100.00% (10/10, 0 noise lines excluded) |
Member
Author
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok. Fairly minimal change.
alexey-milovidov
added a commit
that referenced
this pull request
Mar 30, 2026
The EXPLAIN-based plan check for consecutive Expression steps was unreliable: it returned the same result on both the master binary (without the plan-level fix) and the patched binary because other plan optimizations also create consecutive Expression steps. The actual runtime fix for the `Block structure mismatch in UnionStep` exception was merged via PR #99515, which moved the debug assertion in `UnionStep::updatePipeline` after the header conversion code. This PR's plan-level fix in `optimizeUseNormalProjections` is a defense-in-depth measure that prevents the header mismatch from reaching the pipeline build stage. Keep only the query correctness check as a regression test. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
alexey-milovidov
added a commit
that referenced
this pull request
Mar 30, 2026
The bugfix validation test was failing because the query-success check alone cannot distinguish between master and this PR — PR #99515 already handles the header mismatch at pipeline level, so the query succeeds on both. Add a `setStepDescription` call to the converting `ExpressionStep` in `optimizeUseNormalProjections` so it appears as "Convert projection output to match expected header" in EXPLAIN output. The test now checks for this specific step description, which is absent on master and present with this fix. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UnionStep" exception in debug/sanitizer buildsUnionStep::updatePipelinefired before the existing header conversion code could fix the mismatch, causing a fatal errorReadFromMergeTreeoutput viaActionsDAG::updateHeaderthat are not consumed by the expression DAG above, causing plan headers and pipeline headers to divergeTriggered by test
03722_normal_projection_key_columns.sqlwith parallel replicas +query_plan_remove_unused_columns = 0(stress test settings).Fixes #96131
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=73f45b0717e3a4763b7d1cde71950a076b5b00c7&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_msan%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
🤖 Generated with Claude Code