Repository navigation
Fix block structure mismatch in removeUnusedColumns optimization - #98431
Merged
alexey-milovidov merged 4 commits intoMar 3, 2026
Merged
Conversation
In `addDiscardingExpressionStepIfNeeded`, when all column names between a parent's input header and a child's output header match, the function returned without updating the parent's input header. However, column representations could differ (e.g., `ColumnConst` vs materialized) — this happens when `JoinStepLogical::updateOutputHeader` materializes its `__join_result_dummy` constant column. The parent's stored input header remained stale, causing the `checkHeaders` debug assertion to fail with "Block structure mismatch". Now, when column names all match but the blocks differ structurally, sync the parent's input header with the child's actual output header. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98373&sha=d179a2f6d23d2bd8c4328fc54902b73b8b1a6a13&name_0=PR&name_1=BuzzHouse%20%28amd_debug%29 Closes #92845 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
Member
Author
|
Can we construct a test? |
Exercise the `removeUnusedColumns` optimization with various JOIN patterns where output columns are unused, triggering the `__join_result_dummy` column path in `JoinStepLogical`. This is a regression test for the block structure mismatch fixed in the previous commit. Co-Authored-By: Claude Opus 4.6 <[email protected]>
alexey-milovidov
commented
Mar 2, 2026
…mismatch The previous test queries did not trigger the bug in debug builds. The key ingredient is a nullable expression referencing columns from both sides of the join (e.g., `and(t1.b = t2.b, NULL)`) combined with a WHERE clause on the same cross-table expression and DISTINCT or GROUP BY ALL. This causes `ExpressionStep::removeUnusedColumns` to update its output header via `ActionsDAG::updateHeader`, where constant folding changes a column from materialized to Const representation, while the parent step's input header retains the stale representation. Co-Authored-By: Claude Opus 4.6 <[email protected]>
alexey-milovidov
deleted the
fix-block-structure-mismatch-removeUnusedColumns
branch
March 3, 2026 17:42
3 tasks done
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
removeUnusedColumnsquery plan optimization (STID: 0993-29ef)addDiscardingExpressionStepIfNeeded, when column names match between a parent's input header and a child's output header but column representations differ (e.g.,ColumnConstvs materialized), the parent's input header was not updated, leaving it staleJoinStepLogical::updateOutputHeadermaterializes its__join_result_dummyconstant column after all join outputs are removedCI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98373&sha=d179a2f6d23d2bd8c4328fc54902b73b8b1a6a13&name_0=PR&name_1=BuzzHouse%20%28amd_debug%29
#98373
Closes #92845
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix block structure mismatch exception in
removeUnusedColumnsquery plan optimization whenJoinStepLogicalmaterializes its dummy column.🤖 Generated with Claude Code
Version info
26.3.1.343