Repository navigation
Speed up JSON subcolumn lookup with reusable serializations - #113099
rorylshanks wants to merge 72 commits into
Conversation
The change from `return` to assigning `res` in `IDataType::getSubcolumnData` was a no-op: when `throw_if_null` is set, `getDynamicSubcolumnData` already throws by itself, so falling through to the `ILLEGAL_COLUMN` check below cannot change the outcome. It is unrelated to the serialization-free subcolumn type lookup this pull request adds, so restore the original control flow to keep the diff to the change being made. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Preserve `getSubcolumnData` precedence for prefixed typed paths and make `getSubcolumnType` throw for a known-missing subcolumn. Add a repeatable many-part performance benchmark with a non-JSON control query. Related: ClickHouse#113099
|
Workflow [PR], commit [811c621] Summary: ❌
AI ReviewSummaryPR #113099 makes Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; standard CI must complete successfully. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes34 object files changed (-41.21 KiB total), 0 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 units139 translation units recompiled, 1083 s compile time in total, 139 of them have a recent master baseline. |
|
📊 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 changes only how JSON-typed columns are serialized: SerializationJSON becomes poolable, and parser and extraction-tree state moves to a per-thread cache. None of the flagged ClickBench or TPC-H queries reads a JSON column. All ten flagged queries got faster with less CPU. That pattern fits a base build one release behind (26.9 master vs 26.10 source) better than it fits this diff. ClickBench Q18 (-26.6%) and Q32 (-48.5%) are big enough that their verdicts stand automatically, but the same reasoning applies to them, and re-running against an exact-base build should confirm. The other eight are downgraded to not sure. 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 (3 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
|
Avogar
left a comment
There was a problem hiding this comment.
Thanks for digging into this - the problem you found is real, but I don't think we can take this approach.
It adds a second implementation of JSON subcolumn semantics next to the serialization-based one, and the two have to agree forever. The three bail-outs that preserve "serialization enumeration precedence" show how subtle that agreement is, and nothing enforces it: the next change to JSON subcolumns (a new prefix, a new type-hint rule) will silently diverge in one of the two paths. It is also narrow: the hook is only consulted when DataTypeObject is the outermost type, so Array(JSON(...)), Tuple(..., JSON(...)) or a JSON inside Dynamic keep paying the full price, and the readers, which resolve subcolumns through getSubcolumnData, are not helped either.
More importantly, it treats one caller instead of the cause. Constructing a serialization for a JSON type is O(typed paths): DataTypeObject::doGetSerialization builds a serialization per typed path plus a whole JSONExtractTree, and the tree is used only by text deserialization. So every metadata lookup and every part read pays for a JSON parser tree it will never touch, and the read path still pays it after this PR - locally, a query reading a typed path subcolumn (which never goes through tryGetSubcolumnType) is still an order of magnitude above the floor on this schema.
What I think we should do instead, roughly in this order:
- Make constructing a
JSONserialization cheap. Move the extract tree and its mutable caches out of the serialization to the parsing site, so the object becomes immutable, poolable by type, and independent ofallow_simdjson(which today is baked in at construction time from whatever context happened to build it). Then it is built once per distinct type instead of once per part, for top-level and nestedJSON, and for readers as well as metadata lookups. - Stop rebuilding what already exists. The part keeps the serialization of every column it stores, interned and shared across all parts with the same schema (
SharedPartColumns), so the reader can take it and resolve the subcolumn against it rather than constructing a new one. I tried this locally and it removes all serialization construction from the read path. - Memoize the dynamic subcolumn resolution where it actually repeats, next to the existing memo in
ColumnsDescription. This also covers query analysis, which matters here: with every part pruned, so that nothing is read at all, this query still spends a large share of its time resolvingjson.targetagainst the type at analysis time. That part is per query, not per part, so "the type is resolved per part" describes only half of the cost. - Along the way, the readers resolve the same name several times per read task (and per PREWHERE step); resolving once is a free win independent of everything above.
None of these duplicate the resolution logic, and each is independently useful. The performance test is a good idea in any case - worth keeping with whichever change lands, ideally extended so it also guards the part of the cost that stays after this PR.
If you have time to work on any of those - feel free to do it, ask me any questions or ask for a review.
Check regular subcolumns in the part metadata before invoking the existing serialization-based presence check. Preserve the existing lookup for dynamic paths and the custom serialization handling for `Quantize`. Cover both compact mark formats, renamed columns, and dotted-name collisions. Extend the existing performance test to both compact layouts. Local medians improved by 21% without substream marks and 55% with them; dynamic-path and wide-part controls showed no significant change. Builds and six focused checks passed. Related: ClickHouse#110957 Related: ClickHouse#113099 (review)
JSON subcolumn lookup with reusable serializations
Document parsing-state ownership and the child pooling requirement. Add a query with no matching partitions to isolate subcolumn resolution during query analysis. Related: ClickHouse#113099 (review)
The Fast test build enables `SimdJSON` but omits `RapidJSON`. Selecting `allow_simdjson = 0` therefore reaches `DummyJSONParser` and raises `NOT_IMPLEMENTED`. Use the existing `no-fasttest` tag, as other tests of both parsers do, and retain both parser checks in full stateless builds. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=113099&sha=8a61548fd2fcbd0c4422397009965a74e6ae4217&name_0=PR&name_1=Fast%20test Related: ClickHouse#113099
Move allocation-free typed-path validation from `DataTypeObject` construction into `doGetSerialization`, after the cache lookup. Existing alias metadata can be parsed and attached again, while unsupported schemas still fail when a serialization is requested. Restore the aggregate-state version traversal test and cover attachment, reattachment, and reads through legacy aliases with aggregate-state and numeric-key map paths. Update the `Native` specification's validation note. Related: ClickHouse#113099 (comment) Related: ClickHouse#113099
Key both per-type cache entries by the effective session timezone as well as serialization settings. Typed `DateTime` and `DateTime64` serializers capture that timezone, so a reused table type must rebuild them when it changes. Keep warm reuse and bounded ownership. Cover whole-object output across timezone changes, including nested paths and explicit UTC paths. Check default and nondefault cache reuse across query scopes and settings changes within one context. Update the `Native` specification note. Related: ClickHouse#113099 (comment) Related: ClickHouse#113099
…alidation-test-20260922
|
Investigated. That report is the #120462 shape, not anything about your change. Its job log has eight On the fix: #118708 is mine and I closed it unmerged, so it covers nothing. What landed for this class is #121048, merged 2026-09-21 16:14 UTC. It does not cover your report, and that is deliberate. It greens the check when the cluster answered nothing to a query ( Nothing is left to do on this PR: the next run failed on the sibling shape (readiness fine, every POST timing out, I cannot read |
Use the timezone carried by format settings for implicit `DateTime` and `DateTime64` text output. This keeps typed and inferred `JSON` values stable when parsing runs without a query scope. Related: ClickHouse#113099 (comment)
…Settings` Remove `FormatSettings.json.session_timezone` and `json.allow_simdjson`, and the timezone plumbing that they required in `JSONExtractTree`, `SchemaInferenceUtils` and `SerializationDateTime`. The thread-local parser state cache now has the same lifetime as `DataTypesCache`: it is released when the thread starts serving another query context, or when `session_timezone` or `allow_simdjson` changes in place. Extraction trees are built under the current query timezone, as on `master`, and parser selection is resolved once per query context instead of per row. Also restore `buildJSONExtractTree` to the `master` version: nothing instantiates the `validate_only` mode any more. Related: ClickHouse#113099 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… a separate PR Pruning typed paths during subcolumn lookup is independent of making `JSON` serializations reusable, so it is kept out of this change to reduce its scope. Related: ClickHouse#113099 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…tion tree A pooled `SerializationJSON` shares typed-path types that may have been created under another query, so `DateTime` and `DateTime64` nodes without an explicit timezone use the timezone of the query that builds the tree. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Merged current The only failure on the previous head, All review threads are resolved. @Avogar, this implements step 1 from your review; could you take another look? |
# Conflicts: # src/DataTypes/DataTypeObject.cpp
|
🕵 Merged current The previous head failed only in Stress test (amd_debug) with Related: #121413 |
|
Hey @Avogar what do you think of this approach? Is it more in line with what you were thinking? |
`IDataType::getSubcolumnInfo` walks all streams of the type to find the requested subcolumn. For a `JSON` column, this visited every typed path. Now the requested name is passed in `EnumerateStreamsSettings::subcolumn_name`, and `SerializationObject::enumerateStreams` visits only the typed paths equal to the name or to a prefix of it that ends before a `.`, in the same order as before. Other enumerations do not change. Related: ClickHouse#113099 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflict in `DataTypeObject` constructor by keeping both the `has_timezone_dependent_typed_paths` computation and master's `sorted_typed_paths` initialization. Adapt `hasTimezoneDependentSerialization` to master's removal of `IDataType::forEachChild`: use `anyInTypeTree` from `TypeTree.h`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve conflict in `DataTypeObject.cpp`: master removed `containsObjectType` (no users left), this branch removed `Setting::allow_simdjson` (moved into `SerializationJSON`), so both are dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Dear @Avogar, 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. |
…on-subcolumn-type-lookup Conflicts, all from `SHARED` typed paths of `JSON` (`shared_typed_paths`, `DataTypeObject::TypedPathsMap`) landing on master: - `src/DataTypes/Serializations/SerializationJSON.h`, `src/DataTypes/Serializations/SerializationJSON.cpp`: kept this branch's non-template, poolable `SerializationJSON`, and took master's `TypedPathsMap` and `shared_typed_paths_` parameters into its constructor and `create`. The pool hash now also covers the `SHARED` paths, because they change the stream layout. - `src/DataTypes/DataTypeObject.cpp`: kept the cached `doGetSerialization` of this branch and passed `shared_typed_paths` to `SerializationJSON::create`. Kept both master's `SHARED` path check and this branch's `has_timezone_dependent_typed_paths` in the constructor. - `src/DataTypes/DataTypeObject.h`: kept the includes of both sides. Also switched `gtest_serialization_json.cpp` to `DataTypeObject::TypedPathsMap`, which the `DataTypeObject` constructor now takes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
Reading a
JSONsubcolumn rebuilt theJSONserialization many times. The serialization contained a fullJSONExtractTree, but only text parsing uses the tree. For a schema with many typed paths, this made each lookup slow, especially when a query reads many parts.This change implements step 1 from the review: make a
JSONserialization cheap to build and reusable.SerializationJSONis immutable. The existing serialization pool shares it, andDataTypeObjectcaches it.DataTypesCache. It is released when the thread starts serving another query, or whensession_timezoneorallow_simdjsonchanges. It is also cleared when it holds 64 schemas, or after it parses an object larger thanDBMS_DEFAULT_BUFFER_SIZE.DateTimeorDateTime64without an explicit timezone. This is necessary because a pooled serialization can share types that another query created.Typed-path pruning in
SerializationObject::enumerateStreamswas removed from this PR. It is a separate optimization and can be a separate PR.Measurements with 512 typed paths, 96 compact parts, and
max_threads = 1:These numbers are from an earlier revision that also included typed-path pruning. Most of the gain comes from serialization reuse. The added performance tests cover subcolumn lookup and text ingestion.
Related: #110957
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up queries that read subcolumns from
JSONcolumns with many declared typed paths.JSONserialization objects are now reused instead of rebuilt for each lookup.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/113099]