Repository navigation
Fix skip index, sorting key and partition key computed from the wrong column for a subcolumn name two columns share - #127527
Conversation
…d under Sorting key, skip index and partition key expressions are typed against the table's columns description, where a subcolumn name claimed by two columns (the keys of Map `j.m` and the typed or dynamic path `m.keys` of JSON `j` are both `j.m.keys`) belongs to the column it is registered under, and queries read it from that column. The MergeTree write path materialized such an input from the block by a shortest-prefix walk instead, so it took `j`'s path: - a merge wrapped the result in `materialize` and aborted with `Unexpected return type from materialize. Expected Array(String). Got Array(LowCardinality(String))` (AST fuzzer, STID 1611-37da); - an insert, mutation or `TTL GROUP BY` failed (`Unexpected type Dynamic of bloom filter index`, `Bad cast from type DB::ColumnDynamic to DB::ColumnArray`, `Sort order of blocks violated`) or, with equal types, silently built the index, primary key, partition and its min-max index from the other column, so queries using them returned wrong results. Now a subcolumn that the columns description registers is taken from the column it is registered under (and only from it) when computing the sorting key, skip indexes and the partition key and its min-max index on insert, merge, mutation and `TTL GROUP BY` re-sorting, and the merge and the mutation place that column among the ones they read. Names the description does not register keep the previous resolution. Placing the owner of a min-max index input in a row-reducing merge also fixes vertical merges of a ReplacingMergeTree partitioned by any subcolumn (`PARTITION BY t.a`), which failed with `Not found column or subcolumn t.a in block` because the subcolumn's column was gathered, not merged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove a comment in MutateTask.cpp that restates the lambda below it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261023-004500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261022-235800 |
|
cc @Avogar @Algunenano, could you review this and add the |
|
Workflow [PR], commit [a02bb5d] Summary: ✅
AI ReviewSummaryReviewed #127527 at Missing context / blind spots
Final Verdict✅ Approve — no new inline findings; existing resolved threads need no changes. |
A merge that can remove rows recomputes the partition min-max index in the horizontal stage, so the column a partition key subcolumn comes from must be merged, not gathered. Only registered subcolumns were resolved to their column, so a dynamic JSON path such as `PARTITION BY j.p.:Int64` left `j` in the gathering stage and a vertical ReplacingMergeTree merge failed with `Not found column or subcolumn j.p.:Int64 in block`. Fall back to the column the name is a subcolumn of, as the other key columns of the merge do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1159 translation units recompiled, 8561 s compile time in total, 1158 of them have a recent master baseline. Translation units without a recent master baseline:
|
Under the ParallelReplicas configuration the read step is nested inside the parallel replicas plan, so every EXPLAIN line starts with a `│` tree prefix that `trim` keeps. Strip it the same way other EXPLAIN-based tests do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…merges The vertical merge places a key, skip index or partition key subcolumn by the column it comes from. A name that is not a registered subcolumn fell back to the shortest column-name prefix, whatever its type, so with columns `j UInt8` and `j.m JSON` the JSON path `j.m.p.:Int64` was attributed to `j`, `j.m` stayed in the gathering stage, and the merge failed with `NOT_FOUND_COLUMN_IN_BLOCK`. Resolve it with `ColumnsDescription::tryGetColumnOrSubcolumn`, which keeps the registered owner first and then takes the first prefix whose type has that dynamic subcolumn, the same column the block lookup reads it from. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dex-subcolumn-registered-owner Resolve conflicts: master moved the partition min-max index to `MergeTreePartMinMaxIndex` (its `update` takes the registered owner here), and `splitAndModifyMutationCommands` now resolves index input columns with its own type-aware `getColumnNameInStorage`, which already takes a registered subcolumn from its registered owner, so this branch's lambda is dropped in favour of it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed skip indexes, sorting keys and partition keys over a subcolumn whose name another column also claims (for example
j.m.keys: the keys of aMapcolumn`j.m`and the pathm.keysof aJSONcolumnj). Inserts, merges and mutations computed them from the other column, so merges failed withUnexpected return type from materialize, inserts were rejected, or queries using the index or key returned wrong results. Also fixed vertical merges that failed withNot found column or subcolumnwhen the partition key used a subcolumn, or a key or index used aJSONpath whose name starts with another column's name.Description
On 26.8.18.2, a table with
`j.m` Map(String, String),j JSON(`m.keys` Array(LowCardinality(String)))andINDEX i j.m.keys TYPE bloom_filterreturns 0 instead of 200 rows forWHERE has(j.m.keys, 'a'), andOPTIMIZEfails withUnexpected return type from materialize(a debug abort). Found by the AST fuzzer on #127482 (not caused by it): report.Key and index expressions are typed against the table's
ColumnsDescription, which registers such a name under one column, and queries read it from that column. The MergeTree write path instead took the first block column whose name is a prefix and which has the remainder as a subcolumn, so it usedj's path.Now a registered subcolumn is taken only from the column it is registered under when computing the sorting key, skip indexes, the partition key and its min-max index on insert, merge, mutation and
TTL GROUP BYre-sorting; merges and mutations read that column. Unregistered names keep the old resolution, except in vertical merges (below).In parts written before the fix, a merge or
MATERIALIZE INDEXrebuilds skip indexes but not the sort order or partition; such tables need their data reinserted (INSERT INTO new SELECT * FROM old).Vertical merges now also read the owner of a subcolumn partition key when they can remove rows, and take a
JSONpath in a key or index from the column whose type has it. This fixesNot found column or subcolumnforPARTITION BY t.a,PARTITION BY j.p.:Int64andj.m.p.:Int64beside aj UInt8column.The test fails on master and passes with the fix; builds that revert the insert min-max, mutation, merge min-max or
TTL GROUP BYsites each fail their arm. 50 randomized runs and 122 related subcolumn/JSON key and index tests pass.Workflow [PR]
Sync PR [sync-upstream/pr/127527]