Repository navigation
Fix exception in CoalescingMergeTree with const columns from skip index expressions - #96880
Merged
alexey-milovidov merged 3 commits intoFeb 14, 2026
Merged
Conversation
…ndex expressions When a skip index expression produces a constant result (e.g., `ifNotFinite(1, c0)` on an integer column), executing the combined sorting key + skip indices expression adds a `ColumnConst` column to the block. In `SummingSortedAlgorithm::defineColumns`, the `isColumnConst` check was inside the `if (!aggregate_all_columns)` branch, so it only applied to `SummingMergeTree`. For `CoalescingMergeTree` (which uses `aggregate_all_columns = true`), the `ColumnConst` column was incorrectly added to `columns_to_aggregate`. When `finishGroup` called `insertResultInto`, it tried to `assert_cast` the `ColumnConst` to `ColumnVector<int>`, causing the logical error. The fix moves the `isColumnConst` check before the `aggregate_all_columns` branching so it applies unconditionally. Closes #91958 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
Member
Author
|
Looks very reasonable. |
alexey-milovidov
deleted the
fix-coalescing-merge-tree-const-column-from-index
branch
February 14, 2026 23:50
huldarchen
pushed a commit
to huldarchen/ClickHouse
that referenced
this pull request
Oct 11, 2026
With optimize_on_insert, writeTempPartImpl evaluated the combined sorting key and skip index expression on the inserted block and then merged the whole block with the engine's algorithm. The merge treated the skip index input columns as data columns: SummingMergeTree summed them (length(name) 5+5+5 = 15), grouped two mapKeys(statsMap.a|b) inputs into a fake nested map, CoalescingMergeTree kept the last non-NULL a + b, AggregatingMergeTree applied the SimpleAggregateFunction and GraphiteMergeTree rolled them up. The index was then built from values that are not in the stored rows, so queries using it skipped granules with matching rows. For SummingMergeTree a summed index input also counted in the "all summed columns are zero" rule, so rows that must be deleted were kept. Background merges are not affected because MergeTask evaluates the skip index expressions after merging. Do the same on insert: when the block is merged and skip indexes are materialized, evaluate only the sorting key before the merge, then project the merged block back to the inserted columns and evaluate the combined expression on it. Reusing the combined builder keeps one source for index inputs and avoids duplicate columns when an index expression equals a sorting key expression. All other paths run the old code. ClickHouse#96880 hit the same root cause with a constant index input in CoalescingMergeTree and guarded it in SummingSortedAlgorithm; that guard stays because FINAL and PREWHERE still use it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix logical error exception in
CoalescingMergeTreewhen a skip index expression produces a constant column (e.g.,bloom_filteronifNotFinite(1, c0)for an integer column).Documentation entry for user-facing changes
No documentation changes needed.
Summary
When a skip index expression produces a constant result (e.g.,
ifNotFinite(1, c0)on an integer column always returns1), executing the combined sorting key + skip indices expression adds aColumnConstcolumn to the block. InSummingSortedAlgorithm::defineColumns, theisColumnConstcheck was inside theif (!aggregate_all_columns)branch, so it only applied toSummingMergeTree. ForCoalescingMergeTree(which usesaggregate_all_columns = true), theColumnConstcolumn was incorrectly added tocolumns_to_aggregate, causing a logical error:Bad cast from type DB::ColumnConst to DB::ColumnVector<int>.The fix moves the
isColumnConstcheck before theaggregate_all_columnsbranching so it applies unconditionally to all merge tree engine variants.Closes #91958
🤖 Generated with Claude Code
Version info
26.2.1.681