Repository navigation
Take the serialization of a column from the data part in the MergeTree readers - #120632
grantholly-clickhouse merged 17 commits into
Conversation
…ders `IMergeTreeReader` rebuilt the serialization of every column it reads: `getSerializationInPart` called `IDataType::getSerialization`, which builds the whole serialization of the column and composes the requested subcolumn from it. A reader is created per read task and per filter step, so for a `JSON` column every one of them rebuilt a serialization per typed path and a whole JSON extract tree; with a few hundred typed paths that dominated the read. The part already holds the serialization of every column it stores, built with the same call and interned across the parts with the same schema, so take it from there and compose the requested subcolumn from it. Only a serialization that is safe to use concurrently can be taken, which is what `supportsPooling` tells: one serialization of the part is used by all of its readers at once, while a poolable one is shared by all of its users anyway. A subcolumn is always composed from the serialization of its column and never looked up by its own full name, which a column of the part can be named after. The column and its serialization are now resolved in one pass, which shares the lookup of the column in the part and the enumeration of its parent, and removes the duplicated handling of a column missing from the part. Resolving a dynamic subcolumn and answering whether a subcolumn is present in the part - in `MergeTreeReaderCompact` and in `injectRequiredColumnsRecursively` - no longer build a serialization either. Debug build, 100 compact parts of a `JSON` with 256 typed paths, single thread: reading a typed path 0.136 -> 0.046 s, four typed paths 0.476 -> 0.131 s, a filter on a typed path 0.138 -> 0.052 s, and a dynamic path, where reading the data dominates, 0.345 -> 0.233 s. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [49db709] Summary: ✅
AI ReviewSummaryThis PR changes Final Verdict✅ No new blocking findings in the current revision. LLVM Coverage ReportMeasured on commit 49db709.
Changed lines: Changed C/C++ lines covered: 108/110 (98.18%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes290 object files changed (+300.90 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 units3121 translation units recompiled, 18245 s compile time in total, 3121 of them have a recent master baseline. |
… column into the read task Addresses the review concern that `injectRequiredColumnsRecursively`, now resolving the subcolumn against the serialization the part holds, would miss `vec.quantized` and inject the full `vec` column. The part attaches the `Quantize` serialization to its column when loading `columns.txt`, and a `Quantized` column is always dense, so the serialization the part holds is exactly that custom one and exposes the companion subcolumns. The test reads `vec.quantized` (plain and in `PREWHERE`) after `DETACH`/`ATTACH` and checks that it reads far fewer compressed bytes than reading `vec`. It fails when the subcolumn lookup in `injectRequiredColumnsRecursively` is forced to miss. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…ations-in-mergetree-readers Resolved conflicts with #110957 (`JSON` subcolumn serialization cache): the general part-serialization path of this PR (`tryGetSerializationFromPart`) covers the `containsObjectType` branch added on master, so that branch is dropped. Kept master's sharing of `serializations_of_full_columns` for full-column requests in `Compact` parts and its `withRegularSubcolumns` presence checks in `MergeTreeReaderCompact`, combined with `hasSubcolumnInPart`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120632&sha=04e24771f7c7ab4344dddfa9c77da5e27403abba&name_0=PR&name_1=Stress%20test%20%28arm_msan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.
The |
|
Acknowledged. No fix is in progress for this one. My open #115049 lets startup skip a database whose named collection is missing only for engines that keep no local metadata, deliberately not |
|
The fix is in #122753 (test only).
On the server side, |
…ations-in-mergetree-readers
|
🕵 Thanks @groeneai. #122753 has merged, so I merged |
…test
The performance harness expands every `{name}` in a query as a substitution
placeholder, so the `'{'` / `'}'` string literals in the fill query made the
test fail with `Failed to substitute parameters (KeyError: ...)` in both
performance shards that ran it. Double the braces, as other tests do.
https://s3.amazonaws.com/clickhouse-test-reports/PRs/120632/f0c48dd7c22286eed2ce169ab7bc7fba373e8c55/pr/performance_comparison_amd_release_master_head_1_6/report.html
#120632
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Reusing the serialization the part holds was introduced for the types containing an object only, gated on `containsObjectType`, and in three places: the reader, which took it for such a column when it was poolable; `LoadedMergeTreeDataPartInfoForReader::getSerialization`, which composed a subcolumn from the serialization of its column after a lookup by the full name of the subcolumn missed; and the enumeration of the subcolumns of a column in `SharedPartColumns`, which attached the type for such a column. The reader now reuses the serialization of every column whose serialization is safe to share and composes subcolumns from it, so the first two have no remaining caller - a lookup by the full name of a subcolumn, which the second does first, is also what the general rule has to avoid, because a column of the part can be named after a subcolumn of another column. The third changes nothing: the subcolumns a type exposes do not depend on the type being attached to the enumerated data, which `SharedPartColumns.TypedJSONSubcolumnsAreIncluded` keeps checking. With presence answered against the serialization of the part, the lookups of the full name of a subcolumn in the compact reader are redundant too. `containsObjectType` has no users left and is removed. The performance test added here is dropped in favour of `json_subcolumn_serialization_cache`, which measures the same thing across the three layouts of a part. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ations-in-mergetree-readers Resolved the conflict in `IMergeTreeReader.cpp` in favour of the PR: the general reuse via `tryGetSerializationFromPart` replaces master's type-gated reuse, and already handles the case fixed on master (flattened `Nested` members in Wide parts), since `tryGetSerialization` returns null for the synthetic `Nested` column that does not exist in the part.
… to `forEachSubcolumn` in `SharedPartColumns` The serializations of the subcolumns of a wrapped `JSON`, such as `Variant(JSON(...), UInt8)`, depend on the enclosing types: `SerializationVariant::enumerateStreams` builds the variant types only when the type is attached, and without them `VariantSubcolumnCreator::create` does not set `nullable_added`. Without the type, the serializations of the subcolumns that `SharedPartColumns` caches for the part differ from the ones `IDataType::getSubcolumnSerialization` builds from the serialization of the column. This restores the type-gated threading and `containsObjectType`, and adds `SharedPartColumns.WrappedJSONSubcolumnsMatchOnTheFlySerializations`, which fails without it for `JSON(typed UInt64).typed` and `UInt8`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The serialization of a subcolumn can depend on the types enclosing it: `SerializationVariant::enumerateStreams` wraps an element into `Nullable` only when its type allows it, and `VariantSubcolumnCreator::create` leaves `nullable_added` unset without a type. The serializations enumerated without one therefore differ from the ones `getSubcolumnSerialization` builds from the serialization of the column, which always has it. `SharedPartColumns` passed the type only for a column whose type contains an `Object`, which is not the property that matters: the same difference arises for any `Variant`, `Variant(UInt64, UInt8)` included, and `Object` is not even special there - it reports `canBeInsideNullable`, like a number does. So the type is passed unconditionally and `containsObjectType`, whose only user this was, is removed. `SharedPartColumns.VariantSubcolumnsMatchOnTheFlySerializations` covers it with no `Object` involved. The remaining two enumerations that passed no type - in `getSubcolumnNames` and in the collection of the tuple elements on the path to a subcolumn - use the names alone, but pass it now as well, so that a caller reading the type of an enumerated subcolumn always gets one. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
@Avogar, thanks! This PR is good to merge. |
…art in a test The review asked whether the compact reader still finds `vec.quantized` after the part is loaded back from disk, since `05241_vector_search_quantize_codec_read_task_subcolumn` forces wide parts. Add a compact part with substream marks to the test, read `vec.quantized` together with `vec.size0` in both orders and under `PREWHERE` before and after `DETACH`/`ATTACH`, and check the results do not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120632&sha=7d49335031d0f7286aa3048434424f2816be3396&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20targeted%29 ( |
|
Acknowledged. I am investigating the |
|
The fix is in #123638. When The |
|
🕵 Merged |
|
🕵 Merged |
…` in test `05241` Older rows from reruns against the same server could make the scalar subquery return more than one row or duplicate the output. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ations-in-mergetree-readers
|
🕵 The only CI failure, |
Conflicts, all context-only: - SerializationVariant.cpp, SerializationVariantElement.cpp: 26.8 has `clone()` without the clone context (ClickHouse#126298 is not in 26.8); keep it and add only the copies of the new `variant(s)_absent_in_storage` flags. - MergeTreeReaderWide.cpp: 26.8 has `addStream`, not `FileStreams::getOrCreate` (ClickHouse#114252 is not in 26.8); add only the new `isReadWithTypeInPart` before it. Semantic fix: `IMergeTreeReader::hasSubcolumnInPart` (ClickHouse#120632) is not in 26.8, so `isReadWithTypeInPart` uses `type->hasSubcolumn`, as the 26.8 readers already do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts, all context-only: - SerializationVariant.cpp, SerializationVariantElement.cpp: 26.9 has `clone()` without the clone context (ClickHouse#126298 is not in 26.9); keep it and add only the copies of the new `variant(s)_absent_in_storage` flags. - MergeTreeReaderWide.cpp: 26.9 has `addStream`, not `FileStreams::getOrCreate` (ClickHouse#114252 is not in 26.9); add only the new `isReadWithTypeInPart` before it. Semantic fix: `IMergeTreeReader::hasSubcolumnInPart` (ClickHouse#120632) is not in 26.9, so `isReadWithTypeInPart` uses `type->hasSubcolumn`, as the 26.9 readers already do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
IMergeTreeReaderrebuilds the serialization of every column it reads, and a reader is created per read task and per filter step, so one query repeats this many times over. For aJSONcolumn that serialization is proportional to the number of typed paths - one per path plus a wholeJSONExtractTree- so with a few hundred paths the readers spend their time building an object the data part is already holding.Now the reader takes the serialization from the part, which built it with the same call and shares it across all parts with the same schema, and composes the requested subcolumn from it. The column and its serialization are resolved in one pass, and the presence checks of a subcolumn and the resolution of a dynamic one stop building a serialization too.
A serialization is taken from the part only when
supportsPoolingholds, because all readers of the part use one object at once, while a poolable one is what the pool hands out to every caller anyway.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reading columns and subcolumns of
MergeTreetables no longer rebuilds the serialization of a column for every reader: the serialization the data part already holds is reused. The gain is largest forJSONcolumns with many typed paths, where the whole set of path serializations used to be rebuilt per read task and per filter step.Workflow [PR]
Sync PR [sync-upstream/pr/120632]
Version info
26.10.1.1705-master(included in26.10and later)