Repository navigation
Add SHARED typed paths to the JSON type - #127000
Conversation
The subcolumn readers of one column share the deserialize states of their common streams (`Variant` discriminators, the structure of the `JSON` dynamic shared data, sparse offsets): the first reader in a call decodes such a stream and the others take it from the substreams cache without advancing their state. `DeserializationPrefixesCache` cloned every top-level state separately, so each reader got its own copy of a shared state, and `LowCardinality` never put its state into the states cache at all. When the columns cache serves a subcolumn for some granules and not for others, the decoding reader changes between calls and continues from a stale position: wrong values of `JSON` and `Variant` subcolumns, exceptions for `Dynamic` and `LowCardinality`. `DeserializeBinaryBulkState::clone` now memoizes the clones in a context shared by the whole prefixes map and calls the virtual `cloneImpl`, so a state shared before cloning stays shared after it. `LowCardinality` adds its state to the states cache in `deserializeBinaryBulkStatePrefix`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The JSON type accepts `SHARED path Type` arguments: the parser, the AST, the binary type encoding and its docs, the least supertype and the identity conversion between types that differ only in SHARED marks. A SHARED path resolves as a dynamic subcolumn of the type, and the subcolumn enumeration lists it with the static ones. The Object and sub-object serializations dispatch the SHARED paths to the typed shared data serialization inside data parts and serialize them like any typed path elsewhere. The typed shared data of a JSON column stores its SHARED paths in three streams of a part: a header with the serialization version and, in Wide parts, the bytes of every path; the paths' data granule by granule, each path's granule serialized as one unit with a fresh state, blocks cut by the compressor's size rule and once after the granule's last path; and a marks entry per granule with the row count and the start of every path's data, in Wide parts also the end of the block holding its last byte, from the compressor's block-written callback. The Wide writer signals the completion of a granule to the serialization, also for a granule completed without a call carrying its rows, and routes the block-written callback to the stream's compressor. The readers of the SHARED paths of one column share the structure state created with the header. Every reader's prefix registers the paths it reads; the first reader of a call to miss the substreams cache decodes every requested path of the call's granules, seeking to their marks, and caches the columns under the paths' identity elements; the others copy their rows from the cache. A subcolumn of a path is extracted from the decoded path. The sub-object over SHARED paths is a container delegating to one path reader per path. The whole column decodes every granule in order. The Wide reader reports the streams of a column with the size hints of a shared file, so that a SHARED path's size is its share of the typed shared data. Dropping a column removes the files listed in columns_substreams.txt. In the serialization interface: the substream types of the typed shared data, the identity element of a SHARED path rendered in subcolumn names and cache keys but not in file names, the prefetch predicate that excludes a reader of some SHARED paths, the size hint of a shared stream, the granule completion flag, the block-written callback and the serialization version in the serialize settings. The version is the MergeTree setting `object_typed_shared_data_serialization_version` with the single value `v1`. Stateless tests of the type, its resolution and subcolumns, nested types, key ranges and cut calls, merges and mutations including a granule closed without rows under adaptive granularity, ALTER, the part's files and the wire, S3 with the request pattern of path and whole-column reads, replication and backups, scale, the uncompressed cache, concurrent readers and the columns cache, plus a performance test. The JSON type documentation describes the `SHARED` modifier. Co-Authored-By: Claude Fable 5.1 <[email protected]>
# Conflicts: # src/DataTypes/Serializations/SerializationObject.cpp # src/DataTypes/Serializations/SerializationSubObject.cpp # src/Storages/MergeTree/MergeTreeReaderWide.cpp # tests/queries/0_stateless/05401_columns_cache_shared_deserialize_states.sql
The history record of object_typed_shared_data_serialization_version moves to 26.11, the version master is at. system.parts_columns loses its special case for SHARED paths: the general code lists them with their type's sub-columns like other typed paths, with no sizes since they have no files of their own; the references of 05291 and 05302 follow. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
…-plain # Conflicts: # src/Compression/CompressedWriteBuffer.cpp
|
Workflow [PR], commit [a607056] Summary: ✅
AI ReviewSummaryPR #127000 adds Findings❌ Blockers
Final Verdict❌ Block. Resolve exact typed paths before parsing hints and provide experimental control over adoption of the new persistent layout. The latter concern was dismissed by the author and is retained here without another thread reply. |
readMarkDelta initializes its locals, which clang-tidy requires. Test 05291 no longer calls JSONMergePatch, which the fast test build lacks (RapidJSON is not built there); JSONExtract functions show the same thing, that a SHARED JSON value feeds the ordinary JSON functions. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127000&sha=25372333ba5ac91914adca88ea82e7f5a785744a&name_0=PR PR: #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
The previous commit staged the stale local checkouts of contrib/h3 and contrib/zmij by mistake. PR: #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
|
||
| for (const auto & path : sorted_typed_paths) | ||
| /// Only data parts have the marks and callbacks the typed shared data needs; the Native-only versions returned above. | ||
| object_state->use_typed_shared_data = typed_shared_data_serialization && settings.data_part_type != MergeTreeDataPartType::Unknown; |
There was a problem hiding this comment.
[P1] Gate the new persistent layout behind an experimental setting
This enables the new on-disk codec for every JSON(SHARED ...) column without any experimental setting. object_typed_shared_data_serialization_version only accepts v1, so it cannot control adoption of the new format. Unlike exposing an existing serialization through new syntax, this introduces new granule buffering, marks, and shared reader state that permanently determine how parts are stored. New on-disk formats need an explicit experimental opt-in so deployments can prevent their adoption until they are proven safe.
Please gate creation and alteration of new SHARED definitions behind an experimental setting, including nested definitions, and enable it explicitly in the tests. Reading already persisted parts should remain possible independently of that creation gate.
There was a problem hiding this comment.
I am not convinced that this should be experimental. The feature is straightforward and I expect it to be used right away
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes880 object files changed (+781.07 KiB total), 3 added.
719 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 units3562 translation units recompiled, 18449 s compile time in total, 3558 of them have a recent master baseline. Translation units without a recent master baseline:
|
… tests A typed path wins over the other readings of its name: the lookup resolves typed paths before the special subcolumn of the distinct paths and the sub-object and combined prefixes, so a path named like one of them is found. A subcolumn of another typed path with the same name stays behind the typed path, which the unit tests now state. The special case for a name that begins with a type hint is gone: typed paths are no longer matched by the stream walk, so no caller hands a hint without its path to the object, and such a name is a dynamic path like any other. The flaky check runs each changed test repeatedly under the thread fuzzer and fails runs over 180 seconds unless the test is long: the seven tests that took over 120 seconds there carry the tag. 05305 and 05303 send each section's comparisons in one client call and use smaller tables. 05298 prints only the final granule count of the query with two skip indexes, whose order of application is not fixed. 05292 checks the collision of a SHARED path with a subcolumn of another. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127000&sha=d3f0c36a6c05f6fd50b66115804cb6665475b777&name_0=PR PR: #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
The subcolumn lookup of JSON rejects a name that is only a type hint: the hint parser recognizes a hint at the start of the name as one with an empty path, and a hint without a path denotes nothing. This keeps the behavior that the crash regression test 04545 pins, in place of the removed fall-through check. 05303 asserts only that the warm reads used the filesystem cache: the flaky check runs several copies of the test against one cache, and an eviction between the cold and the warm run made the first warm query read from the source again. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127000&sha=5b36629a316ccefc265af88b2c4e96d03e1ef07c&name_0=PR PR: #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…e new server only Two checks of 05301 took a row with any(), whose choice follows the read order, which parallel replicas change; argMin by the key picks the same row everywhere. The performance comparison runs the setup of every test on the reference server too, which does not parse SHARED; the create query of the SHARED table carries do_not_check_in_pr, so that in this pull request the test runs on the new server only, and on both once merged. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127000&sha=2b7a61272065bc6fa8b0977551eab7098dc7da60&name_0=PR PR: #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
The clone of a JSON type keeps its SHARED set (gtest CloneWithChildrenKeepsSharedPaths). The typed paths live in DataTypeObject::TypedPathsMap, an unordered_map with a heterogeneous hasher, so the prefix loop of the sub-column resolution looks a string_view up without a copy, and the loop keeps its resolution of the remainder instead of resolving it a second time. The JSON argument parser never parses a type twice from the same position, which cost 2^depth on a malformed nested type (test 05428). Comment fixes in IDataType.h. #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Cache keys: in the cache-key rendering a JSON path name follows the keyword .object_paths and the identity element of a SHARED path renders as .shared_paths.<name>, so a path named like a stream cannot collide with it (test 05427). The sub-object reader decodes its SHARED paths in one call straight into its columns, without path readers. The granule writer builds the combined column of a path when the writer asks for it. The stored ends of the marks entry are removed together with the block-written callback of CompressedWriteBuffer: the reader never used them. The prefetch of the typed shared data follows the dynamic shared data's rule under merge_tree_prefetch_json_shared_data_substreams, and the header stream is a metadata stream. Comment fixes. #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
system.parts_columns takes every sub-column's size from IMergeTreeDataPart::getSubcolumnSize, which the readers use, instead of looking the sub-column's file up: a sub-column stored in a shared file, such as a SHARED path of JSON, has no file of its own (test 05302). The reader's substreams map is keyed by the requested column names, which fixes the size of the size0 sub-column of a Nested column: the reader reads it as the offsets of the collected Nested column, under another name, and the lookup by the requested name found nothing. getListOfStreamsForColumns is folded back into getListOfStreamsForColumn. #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
05303: the flag helper compared nothing, so the request checks were vacuous; they are real now, with corrected expectations: path a for the seek checks, x > 52 for one granule, one read task per part, plain file names and no columns cache against the randomizer, and a check of the read-through between adjacent granules of a path with small neighbours. 05301: argMin instead of any, which picked another row under parallel replicas. 05304: no count of mutations, which SharedMergeTree records for a lazy-hint ALTER. 05402: the long tag for the flaky check. #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
The typed shared data reader chose its positioned read mode whenever an absolute seek callback was set. The dynamic shared data sets that callback for a whole-path read too, while it hands the value's serialization one sequential buffer and no current-mark callback, so a JSON(SHARED ...) value stored in a Dynamic path was read with the value bytes taken for the granule entry and failed with INCORRECT_DATA after a merge with the advanced serialization. The mode is now selected by the current-mark callback, the one that means the substreams can be positioned, as the dynamic shared data itself does for its streams. Test 05429 covers the advanced and advanced_chunked shared data, Wide and Compact parts, before and after the merge. #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
system.parts_columns asked the part for every sub-column's size one by one, and each miss of the per-part cache built a reader and read the typed shared data header, once per SHARED path. The part now takes the list of a column's sub-columns and lists their streams with one reader (IMergeTreeDataPart::getSubcolumnSizes, MergeTreeDataPartWide's getListOfStreamsForColumns), so the header is read once per column: a part with 600 SHARED paths costs one file open per query instead of 1200. The results still feed the per-part cache. Also std::ranges::fill for a zero-row entry and the marks entry described without the ends, from the review. #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
| prefix, typed_paths, typed_paths_serializations, schema_format, paths_to_skip, path_regexps_to_skip, | ||
| max_dynamic_paths, max_dynamic_types, getDynamicType(), dynamic_path_serialization); | ||
| /// Split requested subcolumn to the JSON path, type hint, and remaining subcolumn. | ||
| auto split = splitPathAndDynamicTypeSubcolumn(subcolumn_name, getTypeOfNestedObjects()->getName()); |
There was a problem hiding this comment.
[P2] Resolve exact typed paths before interpreting type-hint syntax
This splits the requested name before checking whether the full name is a declared typed path. Quoted path names containing .: followed by a backquoted type are therefore reinterpreted as dynamic type hints, including on existing types without SHARED.
Reproduced with this PR head's Fast test binary:
SELECT getSubcolumn(
CAST('{"a":{":`Int64`":"hello"}}', 'JSON("a.:`Int64`" String)'),
'a.:`Int64`');The result is NULL of type Nullable(Int64), although the declared path is a String containing hello. The same happens with JSON(SHARED "a.:`Int64`" String). Previously, the exact typed-path stream matched the full name before dynamic resolution. Here the split produces path a and hint Int64, so the lookup misses the declared path and reads an absent dynamic path instead.
Please resolve an exact full-name entry in typed_paths before parsing hint syntax, and add a regression covering both ordinary and SHARED paths.
There was a problem hiding this comment.
I will make a follow-up fix for that
The flaky check of the private CI, on S3 storage with the metadata in Keeper and the engine replacer, runs the replication test past the 180-second limit. #127000 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Backport #127000 to 26.10: Add `SHARED` typed paths to the JSON type
…previous-commands Resolve the conflict in collectFilesForRenames with ClickHouse#127000: the once-per-column guard of remove_column_streams stays in front of the new remove_stream lambda that reads columns_substreams.txt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under MSan the test runs at 80-90% of the 600 s per-test timeout (master amd_msan: median 470 s, max 532 s over 6 passing runs, one Timeout! at 600.25 s), against 16 s in amd_debug. The failing job's query_log: six single-threaded INSERTs parsing 640 000 JSON documents 246 s, 18 comparison queries over both tables ~300 s, OPTIMIZE FINAL 22 s; the SHARED table and its plain twin cost the same, and the time does not depend on the random settings draw. The body and reference are unchanged, so ASan, UBSan, TSan and the other builds keep running it. Failing job: https://github.com/ClickHouse/ClickHouse/actions/runs/40338606213/job/121633043306 Related: ClickHouse#127000 Related: ClickHouse#115050 Co-Authored-By: Claude Opus 5.5 <[email protected]>
On the committed corpus check() now accepts all 20132 valid statements, rejects 4731 of 4868 invalid ones, and reports every one of the 4638 errors it shares with ClickHouse at ClickHouse's position with its message. The thresholds sit just under these rates, so losing a single statement fails the test; messageMatch is new. The 137 invalid statements that check() accepts are not parser bugs: 124 use SHARED paths in JSON types, which the source accepts and a master build from after ClickHouse/ClickHouse#127000 (1230fe66203) accepts too, and 13 are SYSTEM INSTRUMENT ADD, which a build without XRay does not parse. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under MSan the test takes up to 445 s of the 600 s per-test timeout on master (amd_msan: median 235 s over 37 passing runs in 30 days), against 7 s in amd_debug, and it times out in the private CI's MSan jobs on object storage. Smaller tables do not fit it: on one MSan server half the rows took 0.85x the time and a quarter 0.74x, because most of the cost is per query, not per row. The body and reference are unchanged, so ASan, UBSan, TSan and the other builds keep running it, and under MSan the many-task SHARED read path stays covered by 05303_json_shared_typed_paths_s3. 445 s run: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=2fbf0f458e338daafbd720d14069681c51b557a8&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_msan%2C%20parallel%2C%202%2F3%29 Related: ClickHouse#127000 Related: ClickHouse#127865 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tream-names" This reverts commit 46a479e, reversing changes made to 1e6f88e. The conflicts with the later changes of ClickHouse#127000 to the same code (the cache-key rendering of the SHARED paths of JSON and the sub-column sizes in getAllColumnsSubstreams) are resolved by keeping their behaviour over the pre-ClickHouse#124816 mechanics: stream names built per call and string keys of the substreams caches. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Closes: #117526
Motivation
Every typed path of a
JSONcolumn is stored in aMergeTreepart as a separate column, with its own set of files. A column with hundreds of typed paths produces thousands of files per part, and on object storage every file is a request, so whole-column reads, merges and metadata operations pay per path.Solution
The
JSONtype gets aSHAREDmodifier for typed paths:JSON(SHARED a UInt32, SHARED b String, c String). ASHAREDpath behaves like any typed path: same type, samejson.asub-column syntax, same sub-object and combined sub-column reads, sameALTER, andsystem.parts_columnslists it like the others. The difference is on disk: allSHAREDpaths of a column are stored together in the typed shared data of the part, in a constant set of files however many paths there are, instead of a set of files per path.The data is written granule by granule, path by path, and a marks file records where each path's data starts in every granule. Reading some paths therefore decodes only those paths, while a whole-column read goes through the file sequentially. Readers of several paths of one column share the decoding work through the substreams cache. The header records the bytes of every path, so the sizes of
SHAREDpaths, which thePREWHEREoptimization uses to order conditions, stay known.ALTER TABLE ... MODIFY COLUMNadds or removes the modifier, as a metadata-only change with lazy type hints or as a mutation otherwise, and parts of both layouts are read together. The on-disk format is versioned by the newMergeTreesettingobject_typed_shared_data_serialization_version. OutsideMergeTreeparts, inMemorytables or theNativeformat,SHAREDpaths are serialized like other typed paths.Sub-column resolution of
JSONnow prefers a typed path over a same-named sub-column of another typed path: withJSON(a Tuple(b String), a.b Int64),json.a.bis the typed patha.bof typeInt64, where it used to be theTupleelementbofa. A declared path is the intended reading of its name.MergeTreerejects such types because their stream names collide, so the change is visible only in other engines and inCAST.Tests
Stateless tests cover the type and its resolution, sub-columns and nested types, key ranges, merges and mutations,
ALTER, Compact and Wide parts, S3 request patterns, replication and backups, a thousand paths, and the caches. A performance test compares reads against plain typed paths. TheJSONdocumentation describes the modifier.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the
SHAREDmodifier for typed paths of theJSONtype, for exampleJSON(SHARED a UInt32, SHARED b String). InMergeTreeparts such paths are stored together in a constant set of files instead of a set of files per path, which keeps the number of files and object storage requests per part small for columns with many typed paths, while a read of a path still decodes only that path. The on-disk format is controlled by the newMergeTreesettingobject_typed_shared_data_serialization_version. Sub-column resolution ofJSONnow prefers a typed path over a same-named sub-column of another typed path, for examplejson.a.bofJSON(a Tuple(b String), a.b Int64)is now the typed patha.b;MergeTreerejects such types, so only other engines andCASTsee the change.Workflow [PR]
Sync PR [sync-upstream/pr/127000]
Version info
26.11.1.786-master(included in26.11and later)26.10.3.11