Skip to content

Add substream_naming_version to make Wide part stream file names injective - #119329

Draft
Avogar wants to merge 4 commits into
masterfrom
namespaced-stream-naming
Draft

Avogar wants to merge 4 commits into
masterfrom
namespaced-stream-naming

Conversation

@Avogar

@Avogar Avogar commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Depends on: #115670
Depends on: #115777
Depends on: #116393
Related: #115632

Stream file names of Wide parts are not injective: the Array, Nullable and JSON container substreams contribute nothing to the name, so a nested user-provided name can collide with an automatically generated one. Both streams of Array(Tuple(`size0` UInt64)) compete for size0, and a JSON path named object_structure lands in the same file as the column's structure stream, which corrupts the part.

This adds the substream_naming_version MergeTree setting. Under namespaced every container substream opens a namespace in the file name (arr_elems, null_elems, object_paths), TupleElement uses a uniform separator, and the level number is dropped from .size because ArrayElements already opens a namespace per level. Names become injective, so those collisions become impossible and schemas that are rejected or silently corrupt a part today — `a.b` UInt64 beside a Tuple(b UInt64), or a JSON path named object_structure — become valid and correct.

Each part records the scheme it was written with, as a top-level substream_naming_version key in serialization.json that is independent of serialization_info_version; the two are forward compatibility knobs at the same level, so neither overrides the other. Readers take the scheme from the part, so parts written under either scheme coexist in one table and survive merges, mutations, renames and reattach.

Null maps are numbered per Nullable level since the last emitted component (.null, .null1, ...), which makes the Nullable(Array(...)) chains expressible ahead of support for that type.

The substreams cache is keyed by the full stream file name in the namespaced form, which is injective for every type, so one cache serves every column of a read and a flattened Nested group's columns meet on the shared offsets stream on their own. The wide reader therefore resolves physical columns and no longer needs the collected Nested view.

The subcolumn name resolution work from the pull requests listed above is included here because it cannot be separated: it deletes Substream::NullMapHidden, and without that not every null map of a chain is reachable as a subcolumn. Following the no-stacked-pull-request rule, the dependency is carried in this PR rather than the branch being based on those.

The default is temporarily namespaced so that CI reports every test that pins a stream file name. Before merge it returns to basic, with substream_naming_version added to the test settings randomizer instead.

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added the substream_naming_version MergeTree setting. With namespaced, every container substream of a Wide part opens its own namespace in the stream file name, which makes the names injective and removes collisions between automatically generated names and user-provided ones — for example a Tuple element or a JSON path named size0, null or object_structure. Each part records the scheme it was written with, so changing the setting affects only new parts and existing parts stay readable.


Workflow [PR]
Sync PR [sync-upstream/pr/119329]

`getNameForSubstreamPath` rendered the `Array`, `Nullable` and `JSON` container
substreams as nothing, so a nested user-provided name could collide with an
automatically generated one: both streams of ``Array(Tuple(`size0` UInt64))``
competed for `size0`, and a `JSON` path named `object_structure` was written into
the same file as the column's structure stream, corrupting the part.

Add `substream_naming_version`. Under `namespaced` every container substream opens
a namespace in the file name - `arr_elems`, `null_elems`, `object_paths` - which
makes the name injective, so those collisions cannot happen. `TupleElement` uses a
uniform separator, and the level number is dropped from `.size` because
`ArrayElements` already opens a namespace per level.

Each part records the scheme it was written with as a top-level
`substream_naming_version` key in `serialization.json`, independent of
`serialization_info_version`: a part using the non-default scheme persists it even
when there is nothing else to record. The two are forward compatibility knobs at
the same level, so neither overrides the other. Readers take the scheme from the
part, so parts written under either scheme coexist in one table and survive
merges, mutations and renames.

Null maps are numbered per `Nullable` level since the last emitted component
(`.null`, `.null1`, ...), which makes the `Nullable(Array(...))` chains
expressible before that type is supported.

The substreams cache is keyed by the full stream file name rendered in the
namespaced form, which is injective for every type. One cache therefore serves
every column of a read, and the flattened `Nested` prefix redirect makes a group's
columns meet on the shared offsets stream on its own. The wide reader resolves
physical columns and no longer needs the collected `Nested` view, which is deleted
along with the `share_nested_offsets` flag in the part-columns interning key.

Includes the not-yet-merged subcolumn resolution work this depends on: a subcolumn
name resolves to a substream declared in the type, then to a dynamic one, then to
a generated name, with the listing and the lookup following the same rules in
`subcolumnResolution.{h,cpp}`. `Substream::NullMapHidden` becomes redundant and is
deleted, which is what makes every null map of a chain reachable as a subcolumn.

The default is temporarily `namespaced` so that CI reports every test that pins a
stream file name. It goes back to `basic` before merge, with randomization added
in its place.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`optimize_functions_to_subcolumns` name collision (#115777) merged into master
after this branch was cut, so its files exist on both sides. Master's versions win
there, including the `memory-engine` tag added to
`04935_optimize_functions_to_subcolumns_name_collision` afterwards.

`IDataType::getSubcolumnInfo` keeps this branch's body, which delegates to
`SubcolumnResolution::findSubcolumn`; master's inline implementation and its
`makeSubcolumnInfo` helper are superseded by `subcolumnResolution.cpp`, which
populates the same `substreams_path`.

In `IMergeTreeDataPart::getCompressionCodecForPart` the two sides changed adjacent
lines: master added a warning when no data file is found, this branch takes the
naming scheme from the part. Both are kept.

`MergeTreeData.cpp` loses both conflicting includes: master dropped
`absl/container/inlined_vector.h` and this branch made
`boost/container_hash/hash.hpp` unused by removing `collect_nested` from the
part-columns interning key.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b888182]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
03747_optimize_functions_to_subcolumns_columns_as_substreams FAIL cidb
05099_mergetree_array_missing_elements FAIL cidb
02889_parts_columns_filenames FAIL cidb
00804_test_delta_codec_compression FAIL cidb
02947_merge_tree_index_table_3 FAIL cidb
04267_mergeTreeCodecBlockCounts_basic FAIL cidb
02947_merge_tree_index_table_4 FAIL cidb
02361_fsync_profile_events FAIL cidb
03755_enable_sparse_nullable_consistently FAIL cidb
02869_insert_filenames_collisions FAIL cidb
18 more test cases not shown
Build (arm_tidy) FAIL
Build ClickHouse FAIL cidb
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 11, 2026
`src/TableFunctions` is linted against `std::` containers so that allocations are
tracked.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Avogar added a commit to Avogar/ClickHouse that referenced this pull request Sep 16, 2026
The case asserting that a purely bucketed `Map` configuration stays allowed
also has to pin `serialization_info_version = 'with_types'`. Per-type
serialization versions are only recorded in `serializations.json` from that
version on, so with `basic` the nested `Map` falls back to `basic`
serialization, writes a plain `keys` stream and really does collide with the
user-supplied `a.keys` element. CI randomizes the setting, which is why the
case failed there while the check was right to reject it.

Also drop the claim that no detection is lost by not enumerating dynamic
streams. It does not hold: the shared data of `Object` renders its `paths` and
`values` components as escaped-dot names (`object_shared_data%2Epaths`), so a
declared `JSON` path of that name collides with them under
`object_shared_data_serialization_version = 'map'` and is not caught here.
`basic` stream naming is simply not injective; making it so is the subject of
ClickHouse#119329.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…aming

Resolve the conflict with the move of the settings changes history into the setting declarations
(ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as
trailing arguments of the `DECLARE` of each setting.

- retargeted PR record [email protected] to 26.10 (settings-history check rule)
- semantic merge fixes in non-conflicting files: src/DataTypes/subcolumnResolution.cpp

Also resolved conflicts in:
- `src/DataTypes/IDataType.cpp`
- `src/DataTypes/IDataType.h`
- `src/DataTypes/Serializations/ISerialization.cpp`
- `src/DataTypes/Serializations/ISerialization.h`
- `src/DataTypes/Serializations/SerializationObjectSharedData.cpp`
- `src/Storages/MergeTree/MergeTreeData.cpp`
- `src/Storages/MergeTree/MergeTreeDataPartWide.cpp`
- `src/Storages/MergeTree/MergeTreeReaderWide.cpp`
- `src/Storages/StorageLog.cpp`
- `tests/queries/0_stateless/04927_substreams_cache_key_collision.sql`

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 19, 2026

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-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants