Repository navigation
Cherry pick #111427 to 26.8: Refactor columns deserialization to avoid all assumeMutable calls, simplify the substreams cache, and remove rows_offset - #116497
Merged
robot-ch-test-poll3 merged 23 commits intoAug 26, 2026
Conversation
…ssion PR #109105 replaced `assumeMutable` with `IColumn::mutate` in the deserialization code. When a column is shared via the substreams cache, `IColumn::mutate` clones the whole accumulated column, giving O(rows × granules) cost and a 3–4× deserialization slowdown. Rework the deserialize path so it never clones: - `deserializeBinaryBulkWithMultipleStreams` and its helpers take `IColumn &` instead of `ColumnPtr &`. - The substreams cache never shares a `ColumnPtr`; consumers copy the current range out via `insertRangeFrom`. - `assumeMutable`/`IColumn::mutate`/`const_cast` are removed from the deserialize paths; mutable children come from non-const accessors. - Cache-shared members are dropped from the `Deserialize*State` structs. - The MergeTree reader stack reads into `MutableColumns`. - `SerializationDetached` builds its `ColumnBLOB` in `IDataType::createColumn` and fills it during deserialization, since the `IColumn &` signature can no longer swap the column pointer. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ment-icolumn-ref-deserialize
…lization After merging master, the new `SerializationQuantizedVector` per-part codebook subcolumn deserializes into a `ColumnConst` (one value broadcast over the whole range), which the `IColumn &` deserialize contract cannot swap in. Add `ISerialization::wrapColumnForDeserialization`, which wraps the base `type->createColumn()` into the column layout a serialization deserializes into. Each layer composes through the serialization chain, replacing the kind-stack loop in `IDataType::createColumn`: - `SerializationSparse`/`SerializationReplicated`/`SerializationDetached` wrap into `ColumnSparse`/`ColumnReplicated`/`ColumnBLOB`. - `SerializationWrapper` forwards to nested; `SerializationTuple` wraps each element by its element serialization, so `DataTypeTuple::createColumn(serialization)` is removed. - `SerializationProductQuantizationCodebook` wraps into a `ColumnConst` that its deserialize fills in place (`ColumnConst::setValue`) and grows, so the (large) codebook is never materialized per row. Co-Authored-By: Claude Opus 4.8 <[email protected]>
`LogSource` allocated the destination column with the plain `createColumn()` and, before the `IColumn &` deserialize refactoring, relied on the swappable `ColumnPtr &` to turn it into a wrapped column during deserialization. That escape hatch is gone, so build the column with `createColumn(*serialization)` instead. This matters for subcolumns whose serialization wraps the column (e.g. the quantized-vector codebook, deserialized into a `ColumnConst`). Co-Authored-By: Claude Opus 4.8 <[email protected]>
`DataTypeTuple` no longer overrides `createColumn(const ISerialization &)`, so on a `DataTypeTuple`-typed pointer that name is hidden by the derived `createColumn()` (name hiding applies to every IDataType subclass; real callers use a base DataTypePtr). Call it through a `DataTypePtr` in gtest_datatypetuple_createcolumn_detached, matching real callers. Also drop `virtual` from `IDataType::createColumn(const ISerialization &)` since nothing overrides it now (it just wraps the virtual createColumn()). https://s3.amazonaws.com/clickhouse-test-reports/PRs/111427/71fcf5a9cccdfcada11346e7aceb4e90f4ba419d/build_arm_tidy/job.log Co-Authored-By: Claude Opus 4.8 <[email protected]>
Resolve conflicts from master's substreams-cache-ownership-checks work and the bucketed Map key-order preservation. - Keep the branch's IColumn& deserialize contract and the copy-out (no-share) substreams cache; keep master's size >= num_read_rows chassert guards. - Remove the ColumnsOwnershipValidator subsystem (base hooks, per-serialization forEachColumn/forEachNestedState overrides, and reader/StorageLog call sites); it is vacuous under the branch's ownership model. Preserve the co-located non-validator fixes (Variant/Dynamic popBack, Dynamic/SubObjectSharedData deep-clone in clone(), quantized-vector part-metadata keying). - SerializationNullableWithParentNullMap: deserialize the nested element into a temporary published clean to the cache, then apply the parent null map to an independent insertRangeFrom copy and append it, never mutating a published column. - SerializationMap/SerializationMapKeysOrValues: adopt master's bucket-index order preservation (has_bucket_index, reorder_with_skipped_rows, collect...WithOrder, check_stream_exists_callback plumbing) adapted to the branch's IColumn& model. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rialize API The arm_tidy build is the only CI build that compiles unit_tests_dbms, so it caught two serialization gtests that were never migrated to the refactored `deserializeBinaryBulkWithMultipleStreams(IColumn & column, ...)` signature: they still passed a `ColumnPtr` (which no longer binds to the non-const `IColumn &`), and one used the removed `insert_only_rows_in_current_range_from_substreams_cache` setting. Migrate both tests to create a mutable column and pass it by reference. The removed setting's behavior is now the only behavior of `insertDataFromCachedColumn` (it always inserts the current range from the cache), so the cache-reuse test still exercises the same path; update its comment accordingly. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111427&sha=8e19cadaa417bb9239a937fd28b5c1dca48beee0&name_0=PR&name_1=Build%20%28arm_tidy%29 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…:ClickHouse/ClickHouse into experiment-icolumn-ref-deserialize
rows_offset (the number of leading rows to skip while deserializing a range) is provably always 0 for every caller, so drop it from deserializeBinaryBulkWithMultipleStreams, deserializeBinaryBulk and all their helpers. Removing it deletes the read-side skip machinery: - the skip loops / istr.ignore(size * rows_offset) seeks, - the Map bucketed reorder-with-skipped-rows path (which also removes the latent substreams-cache over-count on bucketed Map), - the Object shared-data granules_offsets / last_incomplete_granule_offset cursors (StructureGranule.offset/.limit continuous-read state is kept), - the SerializationArrayOffsets helper (rows_offset-only), - assorted dead offset arithmetic (e.g. Sparse max_rows_to_read). Load-bearing continuous-read and substreams-cache tail cursors (num_read_rows, discriminators_offset, num_pending_rows, ...) are preserved. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ment-icolumn-ref-deserialize
The CI performance comparison measures only 10 queries per test file, chosen at random each run (ci/jobs/performance_tests.py passes --max-queries 10 for every non-benchmark test, and perf.py does an unseeded random.sample). The combined subcolumn_deserialization.xml had 20 queries, so only a rotating random half was ever measured per run. Split it into two files of exactly 10 queries each so every query is measured on every run: - subcolumn_deserialization_tuple_map.xml: Tuple + Map (basic + bucketed) - subcolumn_deserialization_variant_json_string_array.xml: Variant + JSON + String + Array Also drop the stale "non-zero rows_offset" phrasing from the header comment (rows_offset was removed; the skip index skips whole granules). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Remove a stray `column = std::move(mutable_column)` in `SerializationArray::deserializeBinaryBulkWithMultipleStreams` (the function now mutates `column` in place) and update the array offsets gtest to the new API: `IColumn &`/`MutableColumnPtr` instead of `ColumnPtr`, and no `rows_offset` argument. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The refactoring accidentally changed the error code for reading into a non-empty ColumnReplicated from INCORRECT_DATA to LOGICAL_ERROR. This branch is reachable from untrusted Native-protocol data (a crafted Sparse(Replicated(...)) kind stack seeds a default value into the nested column), so it is a bad-input condition, not a server invariant violation. Fixes 04616_replicated_serialization_oob_index_native_protocol. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ment-icolumn-ref-deserialize
deserializeBinaryBulkWithSizeStream threw LOGICAL_ERROR when the data stream getter returned null, but that is a valid case: a column missing from the part (e.g. a Nested member dropped and re-added, read from a Compact part) has no substreams, so the reader must leave the column empty and fill defaults instead. Match the behavior of the size-stream String serialization on master. Fixes 04845_type_evolution_matrix_nested_multi. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…erialize Refactor columns deserialization to avoid all assumeMutable calls, simplify the substreams cache, and remove rows_offset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #111427
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job