Repository navigation
Fix a Nested member added to a Memory table by ALTER ADD COLUMN reading as empty arrays - #122991
Conversation
…ts siblings For the blocks inserted into a `Memory` table before `ALTER TABLE ... ADD COLUMN` of a `Nested` member, the member was read as empty arrays, and its `size0` as 0, unless another member of the `Nested` was filled in the same `fillMissingColumns` call. So one row changed value with the query shape (`SELECT n.b` vs `SELECT n.a, n.b`), `PREWHERE` over one member and a read of another gave `SIZES_OF_ARRAYS_DONT_MATCH` (ClickHouse#122497), and a row policy on the member showed rows that `MergeTree` hides. The stored block holds the sizes: its arrays of one `Nested` have equal sizes, which inserts and mutations check. `MemorySource` now fills a missing array from the offsets of the first array of the same `Nested` that the block stores, taken from the arrays the table currently has (so never from a column dropped since, which `Memory` still keeps in its blocks). A missing subcolumn of such an array is taken from the filled array, which also avoids the `ILLEGAL_COLUMN` exception for `sizeK` (K >= 1) of a missing multidimensional array. The same helper serves the unfiltered read, the in-source filter inputs and the columns read after the filter, and a block that has all requested columns takes the old path unchanged. Closes ClickHouse#122497 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… `Nested` An array whose name has no dot is not a member of a `Nested`: inserts do not check its sizes against the members (`Nested::validateArraySizes` skips it), and `MergeTree` rejects such a table as a stream name collision. It shares the `n.size0` offsets key with the members only through the stream file name, so it could still lend its sizes to a missing member, both as a sizes source and, as on master, as another column of the same read: `SELECT n.b` and `SELECT n, n.b` returned different arrays for the same row. `findSizesSource` and `getArraysOfRequestedNested` now count only dotted names, and the missing entries are filled together with their sources only, so no other column of the read lends its offsets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…embers An array whose name has no dot (`n`) shares the `n.size0` offsets key with the members of `Nested` `n`, so filling it in the same `fillMissingColumns` call as the source chosen for a missing member gave it that member's sizes. After `n.a` is dropped, `n` is added and `n.a` is added again (its old data is still in the `Memory` blocks), `SELECT n` returned `[]` but `SELECT n, n.b` returned `[0,0]` for the same row. The missing entries without a sizes source are now filled in a separate call that is given no stored column, so no stored array lends them its offsets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The sizes of a missing member were taken by passing its source to `fillMissingColumns`, which matches every array level by stream name. A tuple element is escaped in stream names, so for a source `n.a Array(Tuple(x Array(UInt8)))` the inner sizes stream of `x` has the name of level 1 of a member `n.a.x Array(Array(UInt8))` added later, and that member read the inner sizes of the tuple element (`[[0,0],[0]]`) instead of empty inner arrays (`[[],[]]`). A missing member that has a sizes source is now built directly as an array of default elements of its type with the offsets of the source, and a missing subcolumn of it is taken from that array. Only the entries without a sizes source still go through `fillMissingColumns`, given no stored column. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the comments that narrate the new helpers; keep the Nested membership and equal-sizes invariants, and the outer-sizes note. 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; 4 rounds: one finding in each of the first three, none in the fourth) plus my own cold review in every round.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260929-235400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260929-231800 |
|
Workflow [PR], commit [41dffe8] Summary: ✅
AI ReviewSummaryThis PR teaches Final Verdict✅ No new findings. |
Build profile diff (arm_release)Commit See the job log for details. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed-column-default-expression Conflict in `ReadFromMemoryStorageStep.cpp` with ClickHouse#122991, which fills a missing `Nested` member from the sizes of a stored sibling. Its `fillColumnsMissingFromBlock` now also serves `readColumns`: it builds the sized member over the whole block and cuts it by the read's mask, and with `defaults` it leaves an entry that has a default expression (a `Nested` member included) null for `evaluateDefaults`, as `fillMissingColumns` does with a snapshot. The entries without a sizes source are still filled apart from the read columns, so no stored array lends them its offsets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Before the fix, the placeholder filled for a typed JSON path of an Array(JSON) member had one Array level more than its type, so the FINAL merge of a ReplacingMergeTree aborted in ColumnDynamic::chooseDynamicStructureForMerge (SIGSEGV on 26.6.8.7 and 26.10.2.103). Case provided by the PR assignee. Also drop the Memory comment that predates ClickHouse#122991: Memory now finds the shared offsets in the stored block without a sibling read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #122497
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a member of a
Nestedadded byALTER TABLE ... ADD COLUMNto aMemorytable being read as empty arrays for the rows inserted before theALTER, unless another member of the sameNestedwas read at the same time. It now gets the array sizes of the other members, like inMergeTree. This fixes wrong results ofSELECT,WHERE,PREWHERE,ARRAY JOINand row policies over such a column, andSIZES_OF_ARRAYS_DONT_MATCHerrors.Description
On 26.3 and 26.9, after
ALTER TABLE t ADD COLUMN n.b Array(UInt64)on aMemorytable withn Nested(a UInt64),SELECT n.b FROM treturns[]for a row inserted withn.a = [10, 20]before theALTER;MergeTreereturns[0, 0]. The same row reads[0, 0]whenn.ais selected too,n.b.size0reads0either way, and a row policyUSING empty(n.b)shows rows thatMergeTreehides. On master, withPREWHEREonn.a,arrayMapovern.aandn.bthrowsSIZES_OF_ARRAYS_DONT_MATCH(#122497).Root cause.
MemorySourcefills a column the stored block lacks withfillMissingColumnsover the columns of the current read only, so a missing array gets sizes only from a member of itsNestedread in the same call. The stored block has them: its arrays of oneNestedhave equal sizes, checked on insert and by mutations.Change. One helper for the three fill sites of
ReadFromMemoryStorageStep.cppfills only the columns the block lacks, from the block alone: a missing member of aNestedgets the sizes of the first member of thatNestedthat the block stores and the table still has, so never a dropped column (Memorykeeps those in its blocks). An array without a dot in its name is not a member. A missing subcolumn is taken from the filled array, which also removes anILLEGAL_COLUMNforsize1of a missingArray(Array). A member dropped and added again under the same name still reads its old data until #122954. The open #122604 also changes this function.Validation. The new test fails on master and passes with the fix, 50/50 with randomized settings; mutation arms cover each fill site and the choice of the sizes source; 417 related
Memory/Nestedtests show no fix-only failure.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122991]
Version info
26.10.1.2092-master(included in26.10and later)