Skip to content

Resolve a subcolumn name to the declared substream, then to a dynamic one - #116393

Open
Avogar wants to merge 26 commits into
masterfrom
fix-subcolumn-name-resolution-order
Open

Avogar wants to merge 26 commits into
masterfrom
fix-subcolumn-name-resolution-order

Conversation

@Avogar

@Avogar Avogar commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

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 Tuple element or JSON path could be unreachable, c.size0 and c.size0.size could come from different substreams, and getSubcolumn(arr, 'size0') disagreed with tupleElement(arr, 'size0') on Array(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 a size0 path), while a declared parent keeps its own (a.size0 of JSON(`a` Array(Int64)) is still the sizes of a).

The mapping lives in subcolumnResolution.{h,cpp} now, shared by the listing and the lookup so DESCRIBE cannot contradict a read. Substream::NullMapHidden is deleted as redundant. Code that builds a generated name now verifies the substream instead of trusting the name — otherwise SELECT n.j.size0 on Nested(`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 and StorageHive — share the same listing, so `c0.size0` means there what c0.size0 means in a SELECT.

Upgrade caveat: a MergeTree whose sorting or partition key references .sizeN of an Array(...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: a bloom_filter index, or an index expression such as arr.size0 + 1, stops the table from attaching; a set index fails the queries that use it; a minmax index 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 with ALTER TABLE ... MATERIALIZE INDEX. Drop such an index or change it to length(...) before the upgrade. Projections cannot reference subcolumns, so they are not affected. MATERIALIZED columns keep attaching and their stored values read as before, though an insert that evaluates such a column then fails. With share_nested_offsets (the default), a MergeTree table can no longer have a Nested member named size0, since n.size0 names 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):

  • Backward Incompatible Change

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.size0 on an Array(JSON) column returns the JSON path instead of UInt64 array sizes (use length(arr)), and length / empty on such columns are no longer rewritten to .sizeN. The same order applies to a flattened name read from Arrow, ArrowStream, ORC, Arrow IPC or StorageHive, where `c0.size0` now reads a Tuple field 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 a MergeTree that references .sizeN of an Array(...JSON...) column must be changed to length(...) 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, for minmax, prunes by the old array sizes, returning wrong results until the part is merged or the index is materialized again. MATERIALIZED and DEFAULT columns over such a name keep attaching, but inserts that evaluate them start failing. With share_nested_offsets (the default), a MergeTree table can no longer have a Nested member named size0, 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]

Avogar and others added 3 commits August 21, 2026 14:30
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]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [883f9a3]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, parallel) FAIL
05632_kafka_insert_undelivered_messages FAIL cidb
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) FAIL
05632_kafka_insert_undelivered_messages FAIL cidb
Stateless tests (arm_binary, parallel) FAIL
05632_kafka_insert_undelivered_messages FAIL cidb
Stateless tests (amd_debug, ParallelReplicas, s3 storage, parallel) FAIL
05632_kafka_insert_undelivered_messages FAIL cidb
01414_push_predicate_when_contains_with_clause NOT_FAILED cidb
01283_max_threads_simple_query_optimization NOT_FAILED cidb
01513_optimize_aggregation_in_order_memory_long NOT_FAILED cidb
00542_access_to_temporary_table_in_readonly_mode NOT_FAILED cidb
Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) FAIL
05632_kafka_insert_undelivered_messages FAIL cidb
05320_promql_duplicate_series_check_per_step NOT_FAILED cidb
05350_comparison_tuple_elimination_shared_alias NOT_FAILED cidb
05059_promql_empty_by_group NOT_FAILED cidb
05034_lazy_materialization_column_function_set_capture NOT_FAILED cidb
05595_timeseries_external_targets_truncate NOT_FAILED cidb
05320_promql_duplicate_series_one_to_one_matching NOT_FAILED cidb
05234_promql_result_timestamp_scale NOT_FAILED cidb
04836_time_series_v10_selector_whole_metric_pk_range NOT_FAILED cidb
05273_promql_instant_vector_sorted_by_tags NOT_FAILED cidb
17 more test cases not shown

AI Review

Summary

Reviewed 883f9a32c824fcd027f2fd2321330ccada50b8db. The PR makes subcolumn listing and lookup share declared/dynamic/generated precedence, preserves array levels through shared-data readers, and handles legacy Nested members named size0 without preventing attachment. No new inline findings. Three previously dismissed upgrade problems remain in the current code, including silently incorrect index pruning. CI reports 15,421 passed tests and zero failures; 04936_subcolumn_name_resolution_order and 05872_nested_size0_member_attach both pass at this head.

Consumers traced for the changed result types: ColumnsDescription and SharedPartColumns use the shared listing; getSubcolumn, compressed Memory, wide/compact MergeTree, and Log use resolution or stream identity; Arrow/ArrowStream, Arrow IPC/Flight, ORC, and StorageHive use NestedColumnExtractHelper; shared JSON paths and Dynamic variants carry the original array level. Stored keys, defaults, and skip indexes retain the upgrade problems below.

Findings

❌ Blockers

  1. Existing minmax indexes can silently exclude matching rows. src/DataTypes/subcolumnResolution.cpp:293,346 changes Array(JSON).sizeN from array sizes to JSON data, while MergeTreeIndexGranuleMinMax::deserializeBinary still interprets old granules using the newly analyzed expression type, and minmaxIndexValidator skips validation during attachment. Existing granules no longer describe the expression evaluated by queries. The author confirmed incorrect pruning with old parts; the current patch adds no guard or invalidation. [dismissed by author -- https://github.com/Resolve a subcolumn name to the declared substream, then to a dynamic one #116393#discussion_r4644692116] The upgrade caveat documents the risk but does not prevent silently wrong results. Preserve the old index semantics or disable/reject affected legacy indexes until they are rebuilt.

  2. Existing sorting/partition keys can prevent tables from attaching. src/DataTypes/subcolumnResolution.cpp:293,346 also changes metadata analysis: ORDER BY arr.size0 or PARTITION BY arr.size0 on arr Array(JSON) now produces Array(Dynamic) instead of UInt64. KeyDescription::getKeyFromAST rejects that type with DATA_TYPE_CANNOT_BE_USED_IN_KEY. There is no versioned metadata resolution or compatibility setting. [dismissed by author -- https://github.com/Resolve a subcolumn name to the declared substream, then to a dynamic one #116393#discussion_r3857710524] Rarity does not restore access to an existing table after upgrading. Preserve resolution for stored keys or provide an automatic metadata migration that retains their meaning.

  3. Existing default expressions can break inserts after upgrade. The same resolver change reaches evaluateMissingDefaults in src/Interpreters/inplaceBlockConversions.cpp:331. A stored definition such as arr Array(JSON), len UInt64 MATERIALIZED arr.size0 still attaches, but evaluating the expression now attempts to convert Array(Dynamic) into UInt64, so inserts fail. DEFAULT expressions have the same problem when evaluated. [dismissed by author -- https://github.com/Resolve a subcolumn name to the declared substream, then to a dynamic one #116393#discussion_r4039265018] The current code still reanalyzes stored expressions with the new semantics and supplies no compatibility path. Preserve their original meaning or migrate these stored expressions to the corresponding array-length expression.

Tests
  • ⚠️ Add a focused upgrade regression using parts and metadata written with the old resolver: verify that affected indexes cannot silently prune matching rows, keys remain attachable through the migration path, and stored defaults still allow inserts. The passing tests of newly created tables do not establish these properties.
Final Verdict

Status: ❌ 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.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 25, 2026
Comment thread src/DataTypes/subcolumnResolution.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 883f9a32c with master 5daf2bf2f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

899 object files changed (+261.29 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/DataTypes/subcolumnResolution.cpp.o new 167.18 KiB +167.18 KiB
src/CMakeFiles/dbms.dir/DataTypes/IDataType.cpp.o 275.08 KiB 209.22 KiB -65.86 KiB (-23.94%)
src/CMakeFiles/dbms.dir/Functions/FunctionsConversion.cpp.o 25.88 MiB 25.92 MiB +43.74 KiB (+0.17%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

3274 translation units recompiled, 14304 s compile time in total, 3273 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-data-types Type system & core datatypes used across query planning/execution. label Sep 4, 2026
Avogar added a commit to groeneai/ClickHouse that referenced this pull request Sep 11, 2026
"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.
Avogar and others added 2 commits September 17, 2026 14:35
…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]>
@Avogar
Avogar marked this pull request as ready for review September 17, 2026 15:46
Comment thread src/DataTypes/subcolumnResolution.cpp Resolved
Comment thread src/DataTypes/subcolumnResolution.cpp Resolved
@yakov-olkhovskiy yakov-olkhovskiy self-assigned this Sep 21, 2026

@Ergus Ergus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this is a backward incompatible change instead of a bugfix only right?

Comment thread src/DataTypes/subcolumnResolution.cpp Resolved
Comment thread src/DataTypes/subcolumnResolution.cpp Resolved
Avogar and others added 2 commits September 28, 2026 15:45
…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]>
@clickhouse-gh clickhouse-gh Bot added pr-backward-incompatible Pull request with backwards incompatible changes and removed pr-bugfix Pull request with bugfix, not backported by default labels Sep 29, 2026
@Avogar
Avogar requested a review from Ergus September 29, 2026 11:19

@Ergus Ergus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Avogar and others added 3 commits October 1, 2026 13:46
…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]>
Avogar and others added 2 commits October 13, 2026 16:46
…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]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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.

Avogar and others added 3 commits November 3, 2026 17:15
…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]>
Comment thread src/DataTypes/subcolumnResolution.cpp Resolved
Comment thread src/DataTypes/subcolumnResolution.cpp Resolved
Avogar and others added 2 commits November 19, 2026 20:00
…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]>
Comment thread src/DataTypes/subcolumnResolution.cpp Resolved
Comment thread src/Storages/StorageLog.cpp Resolved
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]>
Comment thread src/DataTypes/DataTypeDynamic.cpp Resolved
… 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 Ergus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but the CI and the comment about skipping indices need to be addressed.

Comment thread src/DataTypes/subcolumnResolution.cpp Resolved
Comment thread src/Interpreters/getColumnFromBlock.cpp Resolved
Avogar and others added 2 commits November 23, 2026 14:54
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]>
Avogar and others added 2 commits November 24, 2026 11:38
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]>

@Ergus Ergus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-data-types Type system & core datatypes used across query planning/execution. pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants