Repository navigation
Conversation
The substreams cache and the deserialize states cache were keyed by the subcolumn name, which escapes nothing, so two streams of one column could share a cache slot even when their files differ: for `Array(Tuple(`size0` UInt64))` the array sizes live in `c.size0` and the tuple element in `c%2Esize0`, but both render to the cache key `size0`. The reader then handed the wrong column to the wrong deserializer, giving wrong values, `CANNOT_READ_ALL_DATA` or a logical error, while the data on disk was correct. Key both caches by the file name rendering minus the column prefix, which is injective, and route the "substream already read" checks in `MergeTreeReaderWide::getStream` and `LogSource` through the same function. This also removes an inconsistency where those checks rendered sparse elements differently from the cache itself. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
They use the same substreams cache as the wide MergeTree reader, so they were broken by the same collision and are fixed by the same change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… one
Subcolumn names are flat: `Array` and `Nullable` pass the nested name through
unchanged, so several substreams can claim one name. Until now the first one the
enumeration happened to visit won, which made a declared name unreachable
(``Array(Tuple(`size0` UInt64))`` exposed the array sizes, not the element), produced
an incoherent tree (`c.size0` was the array sizes while `c.size0.size` was the
element's string sizes), and disagreed with `tupleElement`, which resolves
`Array(JSON).size0` to the JSON path.
Resolve such a name in a fixed order instead: a substream declared in the type
(a `Tuple` element, a JSON typed path), else a dynamic subcolumn the type resolves
in the same place, else the name the serialization generated. A generated name is
not exposed at all when the data can claim it - `Array(JSON)` may contain a `size0`
path and the type cannot say whether it does - while a declared parent keeps its
own: `a.size0` of ``JSON(`a` Array(Int64))`` is still the sizes of `a`, because the
JSON would have to reinterpret a name that `a` already owns.
Move the mapping from substreams to the flat subcolumn namespace out of
`IDataType` into `subcolumnResolution.{h,cpp}`, where the listing and the lookup
follow the same rules, so `DESCRIBE` cannot contradict a read. `Substream::NullMapHidden`
becomes redundant and is deleted, along with the `hasSubcolumn("null")` probe it
needed on every `SerializationNullable::enumerateStreams` call.
Code that builds a generated name and expects that substream now verifies it
instead of trusting the name: without that, `SELECT n.j.size0` on `Nested(j JSON)`
would be redirected to the shared offsets file and silently return other data.
`inplaceBlockConversions` asks a substream question, not a subcolumn one, so it
walks `enumerateStreams` directly.
`arr.size0` on `Array(JSON)` now returns the JSON path instead of `UInt64`, and
`length` / `empty` are no longer rewritten to `.sizeN` there, which reads more data
but returns the same results.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [883f9a3] Summary: ❌
AI ReviewSummaryReviewed Consumers traced for the changed result types: Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Prevent use of legacy indexes whose expression meaning changed, and preserve or safely migrate affected stored key/default expressions. The dismissed findings remain summary-only; no existing thread was reopened or repeated inline. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes899 object files changed (+261.29 KiB total), 1 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units3274 translation units recompiled, 14304 s compile time in total, 3273 of them have a recent master baseline. |
"sizeN" counts Array wrappers from the root of the column, so the array sizes get a different number at every array nesting level. SerializationDynamicElement and SerializationObjectSharedDataPath keep such a name to resolve it again against the type of a dynamically typed value alone, that is at array level 0, when the value comes from the shared variant or from shared data. The name kept the number it was resolved with, so the two resolutions disagreed on the type and insertRangeFrom aborted in IColumn::assertTypeEquality, or, in a release build, segfaulted or returned a wrong size. The name is now renumbered when it is stored. The substreams path that getSubcolumnInfo reports tells whether it really resolved to the array sizes - a name alone cannot, since a Tuple element or a JSON path can be spelled the same - and the array level inside that path is the number the sizes get against the type alone. The user-facing names do not change: they stay relative to the root of the column, as 03813_size_subcolumn_of_dynamic_subcolumn pins them. A name that is not the array sizes is stored unchanged. Such a name can still mean different substreams at different levels, which is the subject of ClickHouse#116393 rather than of this fix.
…e-resolution-order # Conflicts: # src/DataTypes/IDataType.cpp # src/DataTypes/IDataType.h # src/DataTypes/Serializations/ISerialization.cpp # src/DataTypes/Serializations/ISerialization.h # src/DataTypes/Serializations/SerializationArray.cpp # tests/queries/0_stateless/04927_substreams_cache_key_collision.sql
`data.payload.pull_request.assignees[]` is a dynamic JSON path, so `.size0` resolves to the path of that name inside the assignee objects rather than to the array sizes, and `max` rejects the resulting `Array(Dynamic)`. `length` returns the same value per row, so the expected output does not change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Ergus
left a comment
There was a problem hiding this comment.
IIUC this is a backward incompatible change instead of a bugfix only right?
…e-resolution-order # Conflicts: # src/DataTypes/IDataType.cpp # src/Storages/MergeTree/IMergeTreeReader.cpp # src/Storages/MergeTree/SharedPartColumns.cpp
`findSubcolumn` locked onto the first substream whose name prefixes the requested one and whose type can resolve the rest from the data, so a declared substream deeper in the walk never got the chance. For ``Tuple(`a` JSON, `a.b` JSON)`` and `a.b.some.path` both `a` and `a.b` can resolve their rest, and the answer came from the path `b.some.path` inside `a` instead of from the declared `a.b`, contradicting the rule that a declared substream wins. Keep the most specific prefix instead: a longer prefix leaves a shorter rest. A longer prefix that cannot resolve is still not a candidate, so ``Tuple(`a` JSON, `a.b` String)`` with `a.b.foo` keeps answering from `a`. The `Nested` section of the test is dropped for now: reading a `JSON` path from a `Nested(j JSON, ...)` column in a wide part with `share_nested_offsets` fails on master independently of subcolumn resolution, and a fix for that is already in flight. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Ergus
left a comment
There was a problem hiding this comment.
Looking at the test it is not totally clear to me a detail.
The description says that without this change, SELECT n.j.size0 on Nested(j JSON) reads the shared offsets file. But 04936_subcolumn_name_resolution_order.sql uses only non-Nested columns.
IIUC Nested::isSubcolumnOfNested is false for all these tests, so none of the fixes branches runs. What I am missing here?
…e-resolution-order `IDataType::getSubcolumnInfo` keeps the forwarder to the resolver. Master's new `EnumerateStreamsSettings::subcolumn_name`, which lets a serialization skip the substreams that cannot claim the requested name, is ported into the resolver's candidate walk; its exact-match-over-prefix rule is what the resolver already applies. A comment master added referencing the removed `NullMapHidden` is dropped. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`sizeN` on a type that contains JSON names a path, so the array sizes of a nested `Array(JSON)` level are no longer reachable by it. A `Tuple` field declared as `s.size` wins over the virtual `size` of a sibling `s` whichever order the two are declared in, where before the first one listed won. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`NestedColumnExtractHelper` walked the substreams itself and kept the first spelling of a name, which stopped agreeing with `IDataType` once a declared substream began to beat a generated one. It now shares the listing, so `Arrow`, `ArrowStream`, `ORC`, Arrow IPC, Arrow Flight, Delta Lake and `StorageHive` read a flattened name as a `SELECT` of the subcolumn would. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…e-resolution-order Three conflicts, all where master reworked the same lines: - `inplaceBlockConversions.cpp`: the walk stays over substreams, since an element shadowed in the subcolumn namespace still contributes an array dimension, and it now passes the type the way master's rule of always passing the type when enumerating the subcolumns of a column requires. - `IMergeTreeReader.cpp` and `StorageLog.cpp`: includes, both sides kept. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…e-resolution-order One conflict: master reworked the substream-path rendering to feed the pieces to an `append` callback, so the null-map branch takes that form here, minus the `NullMapHidden` this branch deletes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`JSON(a Array(UInt64), a.size0 String)` gives the name `a.size0` to both the declared path and the array sizes of `a`. The declared path wins, as a substream declared in the type does everywhere else, which is also the only way to address it. The sizes of `a` stay reachable as `length`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Dear @yakov-olkhovskiy, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…e-resolution-order Master's SHARED typed paths of JSON reshaped the subcolumn listing: a typed path can now live in the typed shared data of the part, where it has no substream of its own, so `IDataType::forEachSubcolumn` asks every type it reaches for the names it declares but resolves from the data, and the `EnumerateStreamsSettings::subcolumn_name` pruning is gone. Three substantive resolutions: - The listing in the resolver takes that step over, adding each such name as a candidate of its own, so the dedup ranks it against the walked ones. The entry carries the data it was resolved with, which its path alone does not rebuild. - `isDeclaredSubstream` accepts `ObjectTypedSharedDataPath`: a shared typed path is declared like any other, only its data lives elsewhere. - The listing threads master's new array level, and `getSubcolumnInfo` keeps forwarding to the resolver, whose rules master's inlined version does not have. Co-Authored-By: Claude Opus 5 <[email protected]>
A listing is read in the order the names are offered in, so the names a type resolves from the data follow the element they hang off, as they do in `IDataType::forEachSubcolumn`. Co-Authored-By: Claude Opus 5 <[email protected]>
`sizeN` on a type that contains JSON names a path, so it no longer reads the array sizes: the name disappears from a listing, `n.j.size0` of `Nested(j JSON(...))` stops reading the shared offsets of the group, and the sample values of such reads become the path. The flags these tests compare between Wide, Compact and Memory are unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
…e-resolution-order Master moved `Substream`, `SubstreamData` and the deserialize-state structs out of `ISerialization` into `SerializationSubstream.h`. The relocation is taken as is; this branch's two deltas apply in their new places: the `isDeclaredSubstream` declaration stays on `ISerialization`, and the `NullMapHidden` substream type is dropped from the enum in its new header. Also resolved: - `IMergeTreeReader::isSubcolumnOffsetsOfNested` keeps this branch's `NameAndTypePair` parameter and gains master's `[[nodiscard]]`. - `StorageLog.cpp` keeps both new includes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…aths too Two paths still keyed on the old by-name meaning of a colliding subcolumn: - The compressed `Memory` fast path in `getColumnFromBlock` returned a column's array sizes for `size0` by name alone, which is wrong once the element declares the name (`Array(Tuple(size0 ...))`, `Array(JSON)`). It now takes the shortcut only when the resolved stream is the array sizes. - `findSubcolumn` kept the single most specific prefix passing `canResolveDynamicSubcolumn`, a coarse predicate - for `Dynamic` it only checks the leading type name. A longer prefix could pass it, replace a valid shorter one, then fail to resolve, losing the answer. It now keeps every qualifying prefix and tries them most specific first until one resolves. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Three places resolved a subcolumn name by a different rule than the listing or the first lookup did: - A JSON typed path is declared in the type, but the lookup reached it only through a prefix, after every walked name, while the listing offered it right after the element it hangs off. The new `IDataType::getKnownDynamicSubcolumnInfo` resolves only the names a type knows; the lookup takes them at the element's position and the listing resolves its known names with it, so both pick the same winner. With `allow_dynamic_subcolumns` off, `findSubcolumn` resolves no name from the data, which is how the rest after a typed path is checked. - A variant element is now a declared parent, and a variant's null map belongs to the variant of its name, so a JSON inside `Variant` or `Dynamic` claims `size0` and `null` as it does on its own. - A value read whole from shared data or from the shared variant resolved the stored name again at array level 0, after renaming `sizeN`. At level 0 a declared element can own the renamed name, so the read took it. The readers now resolve the original name at the level it was requested at. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… size0 The array sizes of every Nested member are the group's shared offsets already, so `Log` reads a member's `size0` directly instead of renaming it to `n.size0`, which a member named `size0` owns. A wide part that lacks the member reads them through another member of the group, found by the stream its `size0` reads rather than by a name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ergus
left a comment
There was a problem hiding this comment.
LGTM, but the CI and the comment about skipping indices need to be addressed.
A sizes subcolumn is read through a `NamedOffsets` element whose `sizeN` was fixed when the lookup built it, counted from the column root. Advanced shared data stores each path as a column of its own, so a path below an outer array had its sizes stored as `size0` and requested as `size1`, and reading them without the path threw. `NamedOffsets` is now named by the array level in the path it is read at, as `ArraySizes` is when written, so the name matches wherever the serialization is read from. `EnumerateStreamsSettings::array_level` existed only to fix that number and is removed. `Dynamic` took `T.null` for the null map of the whole value even when T cannot be inside Nullable, and then rejected it. Like `Variant`, it now resolves `null` as an ordinary subcolumn of T in that case, e.g. the elements' null map of `Array(Nullable(UInt8))`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The wide reader reads the array sizes of every Nested member as the group's `size0`. Besides reading a member the part lacks, that keeps all readers of the shared offsets stream in one substreams cache and under the group's name for the dropped and missing column checks. Reading a present member's sizes under its own name instead consumed the shared stream once per reader: sizes of two members, or of one member next to another whole member, came out short or failed the range reader's consistency check, and the sizes of a re-added member were discarded (02565, 04845, 05047, 05210). The rewrite is restored. A member named `size0` would take the group's `size0` for itself, so with `share_nested_offsets` `MergeTree` rejects such a member on `CREATE` and `ALTER`, as `Tuple` reserves `null`; a table that has one still attaches, with an error in the log. `Log` keys its cache by the group, so it keeps such a member. Also point the comment of the compressed `Memory` null map read at the rule it follows now. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=116393&sha=b44f7315f4511ba68e240e12114a0a567847bd07&name_0=PR&name_1=Fast%20test PR: #116393 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Logging it on attach left a table that has one reachable, and reading the array sizes of its other members then fails: they are read as the group's `size0`, which the member takes. Such a member is unlikely to exist in real tables and could not be read on `master` either. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…bcolumn-name-resolution-order
Ergus
left a comment
There was a problem hiding this comment.
I would recommend to not throw on attach, or justify the startup failure explicitly in the PR, and add an ATTACH test if possible.
Rejecting such a table on attach stops the server from loading it after an upgrade, while its data is intact: only reading the array sizes of the other members by the group's `size0` is broken. So `ATTACH` logs the definition as incorrect again, as for a file-name collision, and `CREATE` and `ALTER` keep rejecting it. In wide parts, `isSubcolumnOffsetsOfNested` throws `ILLEGAL_COLUMN` when the part's group has such a member, instead of rewriting the request to the name the member takes. Not rewriting it is no option: read under the member's own name, the shared offsets are consumed once per reader. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #115670
Related: #115777
Related: #115394
Subcolumn names are flat, so several substreams can claim one, and until now the first one enumerated won — a declared
Tupleelement or JSON path could be unreachable,c.size0andc.size0.sizecould come from different substreams, andgetSubcolumn(arr, 'size0')disagreed withtupleElement(arr, 'size0')onArray(JSON).Such a name now resolves to: the substream declared in the type, else a dynamic subcolumn the type resolves in the same place, else the generated name. A generated name is not exposed when the data can claim it (
Array(JSON)may hold asize0path), while a declared parent keeps its own (a.size0ofJSON(`a` Array(Int64))is still the sizes ofa).The mapping lives in
subcolumnResolution.{h,cpp}now, shared by the listing and the lookup soDESCRIBEcannot contradict a read.Substream::NullMapHiddenis deleted as redundant. Code that builds a generated name now verifies the substream instead of trusting the name — otherwiseSELECT n.j.size0onNested(`j` Tuple(`size0` UInt32))reads the shared offsets file of the group. The readers that resolve a flattened name against a struct —Arrow,ArrowStream,ORC, Arrow IPC, Arrow Flight, Delta Lake andStorageHive— share the same listing, so`c0.size0`means there whatc0.size0means in aSELECT.Upgrade caveat: a
MergeTreewhose sorting or partition key references.sizeNof anArray(...JSON...)column stops attaching (DATA_TYPE_CANNOT_BE_USED_IN_KEY). A skip index over such a name was built from the array sizes in existing parts: abloom_filterindex, or an index expression such asarr.size0 + 1, stops the table from attaching; asetindex fails the queries that use it; aminmaxindex attaches and prunes by the old array sizes, so queries that use it return wrong results until the part is merged or the index is rebuilt withALTER TABLE ... MATERIALIZE INDEX. Drop such an index or change it tolength(...)before the upgrade. Projections cannot reference subcolumns, so they are not affected.MATERIALIZEDcolumns keep attaching and their stored values read as before, though an insert that evaluates such a column then fails. Withshare_nested_offsets(the default), aMergeTreetable can no longer have a Nested member namedsize0, sincen.size0names the array sizes the members share and the member would take that name from them; a table that already has one still attaches, with an error in the log, but reading the array sizes of its other members from wide parts fails until the member is renamed.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A subcolumn name claimed by several substreams now resolves to the one declared in the type, then to a dynamic subcolumn, and only then to a name the serialization generated; previously the winner depended on enumeration order. As a result
arr.size0on anArray(JSON)column returns the JSON path instead ofUInt64array sizes (uselength(arr)), andlength/emptyon such columns are no longer rewritten to.sizeN. The same order applies to a flattened name read fromArrow,ArrowStream,ORC, Arrow IPC orStorageHive, where`c0.size0`now reads aTuplefield of that name instead of the array sizes, so a structure hint written for the old meaning fails. A sorting key, partition key or skip index of aMergeTreethat references.sizeNof anArray(...JSON...)column must be changed tolength(...)before the upgrade: such a key stops the table from attaching (DATA_TYPE_CANNOT_BE_USED_IN_KEY), and such a skip index either stops it from attaching too or, forminmax, prunes by the old array sizes, returning wrong results until the part is merged or the index is materialized again.MATERIALIZEDandDEFAULTcolumns over such a name keep attaching, but inserts that evaluate them start failing. Withshare_nested_offsets(the default), aMergeTreetable can no longer have a Nested member namedsize0, the name of the array sizes the members share; an existing table with such a member still attaches, but reading the array sizes of its other members fails until the member is renamed.Workflow [PR]
Sync PR [sync-upstream/pr/116393]