Repository navigation
Cache resolved streams in wide part writer - #130784
Conversation
1. Calculate `min_compress_block_size` once in the `MergeTreeDataPartWriterOnDisk` constructor. This avoids per-granule copy of the columns description. 2. Cache resolved streams to avoid streams enumeration and streams name rebuilding in the per-granule and per-block passes of the writer. 3. Add a perf test that writes many streams in small granules to a Wide part.
Refactor the stream getter and the mark getter to use the resolved stream collections built in `addStreams`. This saves building the short stream name and one `std::map` lookup on the hot path.
|
Workflow [PR], commit [7be6d79] Summary: ✅
AI ReviewSummaryThe PR caches resolved streams for Missing context / blind spots
Final Verdict✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units13 translation units recompiled, 103 s compile time in total, 13 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.11 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
# Conflicts: # src/Storages/MergeTree/MergeTreeDataPartWriterOnDisk.h # src/Storages/MergeTree/MergeTreeDataPartWriterWide.h
Resolves a conflict with ClickHouse#131027 writer code after ClickHouse#130784, which changed how `MergeTreeDataPartWriterWide` finds the streams of a column. `addStreams` now registers the streams of every column once, in `resolved_streams_by_column`, and the functions called for every granule, `getCurrentMarksForColumn` and `writeColumn`, iterate that list instead of calling `enumerateStreams` and building the stream names again. - `writeColumn`: both sides added a line at the same place, the count of the rows of a column with the setting `uncompressed_fixed_array_size` and the lookup of the resolved streams. Both are kept. - `getCurrentMarksForColumn`: the check that flushes the buffer of the elements of such a column after every row used the `substream_path` of the callback of `enumerateStreams`, which the loop over the resolved streams does not have. The merge had no textual conflict there, but did not compile. The stream of the elements is now recognized by its name, which `addStreams` records in `FixedArrayColumn::stream_name` and is the `escaped_column_name` of the stream. Co-Authored-By: Claude Opus 5.5 <[email protected]>

MergeTreeDataPartWriterWideused to resolve stream names from the substream path per block (e.g. inwriteColumn) and once per granule (e.g. ingetCurrentMarksForColumnandwriteSingleGranule), which is unnecessary and produces measurable overhead for writes with small granules and many substreams. This is the case for the proposed native histograms implementation (#122051) for theTimeSeriesengine.This PR resolves every stream once when it is added in
MergeTreeDataPartWriterWide::addStreams, thus avoiding stream name building and stream enumeration in the per-granule and per-block passes.The stream getter and the mark getter look up the stream by its full name in the resolved collection, which removes the short name building and a
std::maplookup per call.min_compress_block_sizeis resolved once inMergeTreeDataPartWriterOnDiskto avoid per-granule copying of the column description.The remaining piece of duplicated work is the conversion of the substream path to the full stream name, which can be eliminated as a follow-up.
On a
c8g.8xlargemachine the added perf test shows 1.44x speedup withindex_granularity = 128and 1.05x speedup withindex_granularity = 8192.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Workflow [PR]
Sync PR [sync-upstream/pr/130784]
Version info
26.11.1.2480-master(included in26.11and later)