Repository navigation
Enable sparse serialization independently for typed paths declared inside JSON columns. - #111429
alexey-milovidov merged 114 commits into
Conversation
Add recursive typed-path serialization metadata behind protocol revision 54489. Older peers retain the established dense materialization compatibility path.
Typed-path sparse metadata was introduced behind `serialization_info_version = with_subcolumns`. Mutation planning still used the older parent-column predicate, so it skipped metadata for `JSON`, whose outer column is not sparse even when typed paths are. It also treated any change to the typed-path set as an incompatible structure and replaced the old `SerializationInfoObject`, losing the serialization decisions of retained paths. Centralize the insertion eligibility rule in `shouldCollectSerializationInfo` and use it from mutation planning. For `Object`-to-`Object` schema changes, preserve metadata through `createWithType`; that method maps retained paths, removes deleted paths, and initializes new paths without a second implementation of the mapping logic. Add wide- and compact-part schema-evolution coverage, exercise dynamic and shared `JSON` data in the revised `Native` test, and verify protocol interchange between the built 26.7.1.1 server and 26.6.2.81. The integration test also covers an S3-backed mutation followed by a final merge. Document that `with_subcolumns` must wait until all replicas understand the new part metadata. On the official 10-million-row JSONBench Bluesky slice, `commit.record.reply.parent.uri` is present in 4.76% of rows. Across 200 hot single-thread iterations, sparse typed-path scans reduced p50 from 17 ms to 10 ms for `countIf` and from 15 ms to 10 ms for `sum(length)`, while an ordinary sparse column took 9 ms. The profiled scan decompressed 4.30 MB instead of 80.0 MB and used 0.44 MB instead of 0.85 MB peak memory. The five official queries that do not read the sparse path remained within 4% at one thread.
Resolved conflict in `docs/reference/settings/merge-tree-settings.mdx`: `master` removed the locally autogenerated settings block from that file, so the regenerated block from this branch is dropped. The setting descriptions the branch changed live in `src/Storages/MergeTree/MergeTreeSettings.cpp` and are preserved.
Resolve the only conflicts, which are both from the documentation reorganization on master: `docs/en/interfaces/specs/NativeFormat.md` and `docs/en/interfaces/specs/NativeProtocol.md` were deleted and their content now lives at `docs/reference/interfaces/specs/NativeFormat.mdx` and `docs/reference/interfaces/specs/NativeProtocol.mdx`. Take master's deletion of the old paths and port this branch's specification changes to the new ones: - recursive `kind_stack` now covers named subcolumns, not only `Tuple` elements; - the `JSON` typed-path entries and their lexicographic ordering at revision `54489`; - the `DBMS_MIN_REVISION_WITH_JSON_TYPED_PATHS_SERIALIZATION` row in the backward-compatibility table; - sparse declared typed paths in the `JSON` FLATTENED section; - the `JSON_TYPED_PATHS_SERIALIZATION` row in the protocol feature table. `DBMS_TCP_PROTOCOL_VERSION` merged cleanly: master is still at `54488`, so this branch keeps `54489`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…-typed-paths # Conflicts: # docs/reference/interfaces/specs/NativeProtocol.mdx # src/Core/ProtocolDefines.h # src/DataTypes/DataTypeObject.cpp # src/DataTypes/DataTypeTuple.cpp # src/DataTypes/DataTypeTuple.h # src/DataTypes/IDataType.h # src/DataTypes/Serializations/SerializationInfoTuple.cpp # src/Formats/NativeReader.cpp # src/Formats/NativeWriter.cpp
Preserve typed-path serialization metadata when a mutation rewrites a stale `JSON` column at its current storage type. Accept derived `SerializationObject` implementations and include the complete `IColumn` definition required by the merged code.
|
Workflow [PR], commit [96eb61b] Summary: ✅
AI ReviewSummaryReviewed #111429 at The new column form was traced through these consumers:
Focused runtime checks using the head's CI binary passed for whole-value output, subobjects, functions, aggregation, grouping, sorting, joins, wrapper conversions, copying, merging, and nested schema evolution. Metadata confirmed sparse paths before and after evolution. The head's Final VerdictStatus: ✅ Approve |
|
📊 Cloud Performance Report
Release-transition baseline: compared against the most recent available 26.9 masters at or before the trusted base-commit anchor because no 26.10 master baseline exists there. This PR adds sparse serialization for JSON typed paths, behind the opt-in serialization_info_version = 'with_subcolumns'. Plain-column tables like ClickBench hits and TPC-H are unaffected: the new hooks return false for non-JSON types. Every flagged result is an improvement, and none can plausibly come from this diff, so most were downgraded to not sure. ClickBench Q18 (-26.1%) and Q32 (-48.5%) are large enough that their verdicts are locked and could not be downgraded. All the improvements are more likely baseline drift, since the source build is v26.10 and the baseline is v26.9. Rerun against a baseline built from the PR's exact base commit before crediting this PR with any speedup. clickbench🟢 2 improved · Flagged queries (7 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_officialFlagged queries (4 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
New tuple elements remain `Default` during mutation and become `Sparse` after a merge. Preserve the sparse assertions only for retained elements.
Avoid forwarding outer serialization info through typed-path wrappers, preserve matching nested serialization-info types during schema evolution, and cover the mutation-to-merge kind transition.
`LOGICAL_ERROR` terminates debug and sanitizer processes before the exception assertion can run. Follow the existing release-only pattern used by malformed serialization-info tests.
The invalid internal serialization state cannot be exercised through SQL, while debug and sanitizer builds terminate before an in-process exception assertion can run. Keep the fail-fast guard without a permanently skipped gtest.
Build profile diff (arm_release)Commit See the job log for details. |
…-typed-paths Resolve conflicts with the switch from `forEachChild` to indexed children and `doCloneWithChildren` in `DataTypeObject`. Build the per-path serialization infos from master's `sorted_typed_paths` instead of sorting the paths again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rt_type` The test was switched to `Nullable(JSON)` to cover reusing serialization info through `Nullable`. That support was removed when the PR was trimmed back to typed paths of `JSON` columns: typed paths of `JSON` nested in `Nullable` stay dense, so the part never had `x` sparse and the expected `Sparse` could not hold. Go back to the plain `JSON` column, which covers what the test is about: keeping typed-path serialization info when a full-part mutation rewrites a `JSON` column whose type in the part is stale. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-typed-paths Conflicts: - `src/DataTypes/DataTypeObject.cpp`: master moved `CANNOT_COMPILE_REGEXP` within the error code list; kept master's declaration and dropped the duplicate. - `src/DataTypes/Serializations/SerializationObject.cpp`: kept the PR's `SerializationInfoObject.h` and `SerializationObjectTypedPath.h` includes next to master's include list. - `src/Formats/NativeWriter.cpp`: kept master's new `setAggregateFunctionStateVersions`, and used master's `removeSpecialRepresentations` on the PR's materialized `result_column` for old clients. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
`DataTypeObject::createColumn` taking a serialization looked up every typed path of a sub-object type in the typed path serializations of `SerializationSubObject`. Since master added `SHARED` typed paths, the `SHARED` ones are not there: they are read together by the typed shared data serialization. Reading `j.^a` of `JSON(SHARED a JSON, SHARED a.b Int64)` threw `std::out_of_range` (`05292_json_shared_typed_paths_resolution`). Master now creates the column layout a serialization deserializes into through `ISerialization::wrapColumnForDeserialization`, so drop the override and let `SerializationSubObject` wrap the columns of the typed paths it reads itself, like `SerializationObject` does. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=111429&sha=f5e10da0423243d5c6662602baaacc1087dab320&name_0=PR&name_1=Fast%20test PR: ClickHouse#111429 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
A `SHARED` typed path is stored in the typed shared data of a part. The serialization info of the `JSON` column chose `Sparse` for it like for any other typed path, but `SerializationObjectTypedSharedData` decodes a path read as a subcolumn into a column of the default layout, so reading such a path with `Sparse` serialization fails on `assert_cast` to `ColumnSparse`. Do not choose a kind for the serialization info of a `SHARED` path, and do not carry the kind of a path over when it becomes `SHARED` in `SerializationInfoObject::createWithType`. The other typed paths still become `Sparse`, including the ones next to a `SHARED` path in a sub-object, which the new test covers too. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
`SerializationObject::wrapColumnForDeserialization` and `SerializationSubObject::wrapColumnForDeserialization` replace the typed path columns through `ColumnObject::getTypedPaths`, but `ColumnObject` keeps raw pointers to them in `sorted_typed_path_columns`. The pointers were left dangling, and filling defaults of the typed paths while parsing `JSON` dereferenced them (segmentation fault in `05022_json_max_dynamic_subcolumns_in_parsing_after_default_rows`). This became reachable when the `DataTypeObject::createColumn` override taking a serialization was removed, because columns of `JSON` are now always created through `wrapColumnForDeserialization`. Make `ColumnObject::rebuildSortedTypedPathColumns` public and call it after the typed path columns are replaced. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=111429&sha=446f3b5a240509a6585fa01b230a1e7348ac7bce&name_0=PR&name_1=Fast%20test PR: ClickHouse#111429 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
…yped-paths Conflict resolutions: - `SerializationInfoTuple`: kept the PR's move of the shared logic into `SerializationInfoNamed`; ported master's exclusion of `Replicated` (besides `Detached`) for element kinds into `SerializationInfoNamed::deserializeFromKindsBinary`, and added master's `[[nodiscard]]` annotations to the moved/new declarations. - `NativeWriter`: kept materializing `JSON` typed paths and used master's `getSerializationInfoSettings`; also materialize them on master's new cached-type path, so the `Native` wire layout stays unchanged there too. - `SerializationObject` / `SerializationSubObject`: ported the PR's `wrapColumnForDeserialization` overrides to master's `createColumnForDeserialization(const IDataType &)`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged current The previous @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=111429&sha=49113872814712fd28366ef8ed3fe841ea6de7ea&name_0=PR&name_1=La%20Casa%20Del%20Dolor%20%28amd_debug%29 ( |
|
This is already fixed by #128898 (merged 2026-11-05), and this PR's tree includes it since your master merge. It is the same STID 4605-4c8e and stack ( The linked run is head 4911387 (2026-11-04 12:36 UTC), before the fix merged. CIDB has 5 rows of this signature, all between 2026-11-03 and 2026-11-04 15:58 UTC, and none on master or any PR since. |
`modernize-use-nodiscard` failed the `arm_tidy` builds on `SerializationInfoSettings::shouldCollectSerializationInfo`. Also cast the result of `getTypedPathInfo` to `void` inside `EXPECT_THROW` in `gtest_serialization_info.cpp`: the getter is `[[nodiscard]]`, so the unit tests did not compile with `-Werror,-Wunused-result`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=111429&sha=838799ec1d1ea021c30c5fb16212df49488d647f&name_0=PR&name_1=Build%20(arm_tidy%2C%204%2F4) ClickHouse#111429 Co-Authored-By: Claude Fable 5.2 <[email protected]>
…h `NativeWriterTypeCache` The cached-type branch of `NativeWriter::write` called `materializeObjectTypedPaths` on the column as is, while `getSerializationAndColumn` first applies `convertToFullColumnIfConst` and `decompress`. A compressed `JSON` column reached the `assert_cast` to `ColumnObject` in `DataTypeObject::getSerializationInfo`, and a constant one kept its typed paths sparse, so the written kinds did not match the data that `writeData` emits (`Bad cast from type ColumnSparse to ColumnVector` exception). Make the column full before materializing typed paths, as on the path without the cache, and add a unit test that writes sparse, compressed and constant `JSON` blocks with and without the type cache. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged current
@groeneai, thanks - the |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=4 K_base=26 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…parse-json-typed-paths" This reverts commit b6f0aca, reversing changes made to 711cfda. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md. Changelog-revert: 133486 111429 Revert "Enable sparse serialization independently for typed paths declared inside `JSON` columns." Changelog-deleted-entry: 111429 [Performance Improvement] [section] * Typed paths in `JSON` columns can now use sparse serialization in `MergeTree` parts when `serialization_info_version = 'with_subcolumns'`, reducing CPU and memory usage when scanning mostly absent paths. [#111429](#111429) ([Rory Shanks](https://github.com/rorylshanks)).
…y-serialization Conflict resolution: - `master` reverted the sparse serialization of `JSON` typed paths (#133486 reverting #111429), which removed `SerializationInfoNamed` and `SerializationInfoObject`. The `checkKindStacks` and `checkKindStackForType` overrides move back to `SerializationInfoTuple`, the ones of `SerializationInfoObject` are dropped together with the class, and `MutateTask` uses `canUseSparseSerialization` again instead of the removed `shouldCollectSerializationInfo`. - `NativeWriter::getSerializationAndColumn`: keep the materialization of non-native `LowCardinality` columns for old peers on top of the reverted code. - `tryGetSerializationHints` now takes the metadata snapshot (#133300): pass it through in the overrides this branch adds for the wrapper storages. - `tests/parallel_replicas_plan_based_blacklist.txt`: `master` removed the whole `UNIQUE KEY` section, because plan-based parallel replicas now keep such reads local (#133744), so `05449_auto_low_cardinality_serialization_unique_key` is not listed anymore. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Typed paths make frequently queried
JSONfields behave like regular columns, but they are currently serialized densely even when absent from almost every row. Dense defaults compress well on disk, yet scans must still decompress and materialize them.This PR adds
with_subcolumnspart metadata and lets each directly declared typed path use the existing sparse serialization independently. A rare path can be sparse while other paths in the sameJSONcolumn stay dense. AJSONelement of a top-levelTuplecolumn is covered too.JSONnested inArray,Nullable, orMapremains valid, but its typed paths stay dense and are not optimized bywith_subcolumns.The
Nativeformat remains unchanged. Typed paths are materialized dense before writing, so this PR adds no protocol revision or recursive wire metadata.On the JSONBench 100-million-row Bluesky dataset, a typed path present in 4.2747% of rows produced these focused hot-cache results:
sum(length(path)), 1 threadcountIf(path != ''), 1 threadsum(length(path)), 16 threadscountIf(path != ''), 16 threadsThis is an opt-in scan optimization. It can increase part-metadata size, insert CPU, and merge memory for schemas with many declared paths, so
serialization_info_version = 'with_subcolumns'should be enabled only after all replicas understand the new part metadata.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Typed paths in
JSONcolumns can now use sparse serialization in MergeTree parts whenserialization_info_version = 'with_subcolumns', reducing CPU and memory usage when scanning mostly absent paths.Workflow [PR]
Sync PR [sync-upstream/pr/111429]
Version info
26.12.1.144-master(included in26.12and later)