Repository navigation
Announce the byte ranges MergeTree will read to the read buffers - #122250
Conversation
Add `ReadBuffer::setRequestMap`: the sorted byte ranges the caller will read, and nothing outside them. An empty map, the default, is the whole file. The compressed buffers and `PipelineReadBuffer` forward it. `ReadBufferFromFileView` shifts it into its slice of the archive and announces the slice by default. `ReaderExecutor` stores the map; nothing reads it yet. MergeTree announces the mark ranges each reader reads over all its tasks: the thread's stripe in `MergeTreeReadPool` and `MergeTreePrefetchedReadPool`, all ranges of the part in the other pools, and the given ranges in merges. A reader reused for the next task gets that task's map. Each stream converts the marks to byte ranges of its file, only when `use_reader_executor` is on. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [8091dba] Summary: ❌
AI ReviewSummary
Findings
Tests
Final Verdict
LLVM Coverage Report |
The map of a part does not change during the query, so the readers get it once, when they are created, and a reader reused for the next task needs no update. This removes the stripes from `MergeTreeReadPool` and `MergeTreePrefetchedReadPool` and the update path through the readers and streams. With a cache, bytes a thread reads past its stripe serve the neighbour thread. Without a cache, a stripe would save at most one window per stream at each stripe boundary. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`ReadBuffer::setRequestMap` takes a `ByteRangeSet` instead of a vector of ranges, so the map merges overlapping ranges itself and can carry the methods the executor needs. `IntervalSet` in `src/IO` is renamed to `ByteRangeSet`. `ReadBuffer.h` now includes it, and the old name clashes with the `IntervalSet` template in `Common/IntervalTree.h`. `ByteRangeSet::add` finds its place by binary search, so ranges added in order no longer scan the set from the front. The new `intersect` and `shift` clip and move the map in `ReadBufferFromFileView`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Patch readers were created with reader settings that carry no request map, so the streams of patch parts announced the whole file. `MergeTreeReadTaskInfo::patch_request_maps` now holds, for each patch part of a part, the patch ranges that the part's readers read: `RangesInPatchParts::getRanges` for all ranges the query reads from the part. The pools compute them after `RangesInPatchParts::optimize`, because the ranges of `Join` patches depend on all parts of the query. Merges use the patch ranges they already compute for their ranges. The maps are fixed for the query, so reused patch readers need no update. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes566 object files changed (+408.40 KiB total), 1 added.
720 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 units3119 translation units recompiled, 18036 s compile time in total, 3118 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.09 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
With parallel replicas, the map of a part holds the ranges of all replicas, while the coordinator assigns each replica a part of them during the query. `MergeTreeReadPoolParallelReplicas` and `MergeTreeReadPoolParallelReplicasInOrder` now give each task the ranges of the part in the current assignment, and a reader reused for the task announces them again. The other pools pass no map, so their readers keep the map of the whole part and get no updates. Maps now exist only with the reader executor. `buildReadTaskInfo` and `MergeTreeSequentialSource` create them only when it is on, and the rest of the code acts only on a map that exists, so the other read paths copy and convert nothing. The fields of `MergeTreeReadTaskInfo` are renamed to `read_request_map` and `patch_read_request_maps`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`describe` lists all ranges of a set with fewer than 10, and the first 4 and the last 4 of a longer one. `ReaderExecutor` logs the request map with it. The request map tests read the range count from the new log line, and they pin the settings that change the layout of the test parts: sparse serialization adds a small stream for each column, the range-splitting injection reads one part as two, and `v1` patch parts can use `Join` patches, which map to all patch ranges of the part. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`ICacheProvider.h`, `DiskCacheProvider.h` and `PageCacheProvider.h` included the header without using it. `ReaderExecutor.h`, which holds a `ByteRangeSet`, now includes it itself. The comments of `ReadBuffer::setRequestMap` and `MergeTreeReaderSettings::request_map` no longer describe the order of the ranges. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…search The intervals are sorted and disjoint, so both skip to the first interval that ends after the start of the range with `std::partition_point`, the same way `add` does, and stop at the first interval past its end. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A ranges refiner (`use_indexes_refiner_in_read_pools`) decides task by task which ranges survive the skip indexes or the projection index, after the map of the part was taken. `MergeTreeReadPoolBase::refineReadRanges` now records the ranges it drops from each part, and the readers of a task get the map without them (`mapWithoutDroppedRanges`), so the ranges of later tasks stay in the map until the refiner drops them. The tasks of a part share one map until the refiner drops more, so a reused reader announces again only then. The prefetched pool passes the same map to the readers it creates in its refining job. Patch readers keep the map of the patch ranges for the whole part. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
With parallel replicas or a ranges refiner, the readers of a task get a map narrower than the part's, but patch readers still announced the patch ranges of the whole part. When the map is narrower, the pool now derives the patch maps from it with `RangesInPatchParts::getRanges`, the function the tasks use for their patch ranges, and caches them for the part until the map changes. New patch readers get them, and `Readers::updateRequestMap` gives them to reused patch readers too. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`recordDroppedRanges` rebuilt the merged set of dropped ranges for every cut, and a new map subtracted all of them from the base again. The dropped ranges are now appended as the refiner reports them, and the map remembers how many of them it already leaves out (`dropped_in_map`), so a new map subtracts only the entries added since. A new base, as a new assignment of parallel replicas, still starts from all entries. `patch_maps_of` is renamed to `patch_maps_source`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
On a case-insensitive disk (macOS), `replaceFileNameToHashIfNeeded` stores every stream under the hash of its name, so `05259`, `05260` and `05261` did not find `k.bin` or `v.bin` in the log. Take the file name from `system.parts_columns.filenames` instead of the `replace_long_file_name_to_hash = 0` pin. Under the load of the flaky check, the insert of 1M rows took up to 157 s and `05261` ran longer than 180 s. Use 100K rows with `index_granularity = 128`, which keeps the portions of the coordinator at about 160 marks. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122250&sha=8bc1cbdcbc905270e722425f492d0e3ca1f98cc5&name_0=PR PR: #122250 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…helpers `subtractMarkRanges` takes `what` as a `std::span`, so the entries of `dropped` that the actual map does not include yet are sorted in place instead of copied. Rename the helpers after what they return: `getActualReadRequestMap` (was `mapWithoutDroppedRanges`), `getActualPatchReadRequestMaps` (was `patchMapsFor`), `announceReadRequestMap` and `updateReadRequestMap`. `PartMaps` is now `PartReadRequestMaps`, with `initial_map`, `actual_map` and `actual_patch_maps`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
An empty set can reach the executor for a caller that reads nothing: a patch part that the task's map does not touch, mark ranges of zero bytes, or a view map outside the view's slice. Without a map, the caller may still read the whole file, so the default does not change. `ReadBufferFromFileView` announces its slice explicitly, and `ReaderExecutor` keeps `std::optional<ByteRangeSet>`. Related: #122250 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR adds a byte-range request map that MergeTree read pools pass down to the read buffers. It is built only when the reader executor is enabled, and the executor only stores the map and logs it at test level. Nothing in the read path uses it to change read-ahead or I/O yet. ClickBench Q31 (+16.2%) and Q30 (+20.4%, inside master's variance band) are both heavy GROUP BY ClientIP aggregations whose wall time grew by about 45 ms while CPU time stayed flat (within about 1%). That pattern does not match extra work from this change, so Q31 is downgraded to not_sure and the Q30 suppression stands. The full diff was too long to review in one piece, and I could not confirm whether the reader executor is enabled in this benchmark setup, so attribution has medium confidence. No tpch_adapted_1_official queries were flagged. clickbenchFlagged queries (2 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_official🟢 No significant changes Debug info
|
The source creates its readers once and never updates their maps, so it does not need a copy of `MergeTreeReadTaskInfo` to carry them. Related: #122250 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`createReaders` and `Readers::updateReadRequestMap` index the patch maps by the position of the patch part. A vector of another size would read past the readers, so it is a `LOGICAL_ERROR`. An empty vector still means no patch maps. Related: #122250 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ngs` Every reader built from a copy of the settings inherited the map, so the index readers had to clear it, and `createReaders` copied the settings only to carry it. Now `IMergeTreeReader` holds the map: `createReaders` sets it on each new reader, and readers pass it to their streams. `MarkRangesPtr` moves next to `MarkRanges`. Related: #122250 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…nt request map `MergeTreeReaderWide::getOrAddStream` also creates streams after the map was announced, for the subcolumns of a `Dynamic` column that it finds in the prefix, so `updateReadRequestMap` never reached them. Each new stream now takes the reader's current map. Related: #122250 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…fallback reader Related: #122250 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…uest_map` In ClickHouse Cloud a compact part keeps up to `compact_parts_max_granules_to_buffer` granules of each column together. With a random size of 112 the whole part was one stripe, the single-buffer reader announced the map of the stripe, and the two key ranges merged into one. The setting has no effect in the public build. CI report: https://d1k2gkhrlfqv31.cloudfront.net/clickhouse-test-reports-private/praktika.html?PR=78395&sha=f877070f763ac37ec47f5cbb8c1612117c72ab4b&name_0=PR Related: ClickHouse/clickhouse-private#78395 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The experimental
ReaderExecutorknows only theread_untilof the current task, and today that bound also caps what it fetches. The next PR bounds a fetch by the window and by the bytes MergeTree will read instead. This PR gives the executor that input; read behaviour does not change.ReadBuffer::setRequestMap(ByteRangeSet): the byte ranges the caller will read until it announces another map; empty = nothing, no map = the whole file; advisory. The compressed buffers forward it,ReadBufferFromFileViewmoves it into its slice of the archive,ReaderExecutorstores it.use_reader_executor.IntervalSetinsrc/IOis renamed toByteRangeSet:ReadBuffer.hnow includes it, and the old name clashes withIntervalSetinCommon/IntervalTree.h.Tests:
05257-05261(wide, compact, packed and patch parts, parallel replicas, refiner),gtest_byte_range_set,gtest_read_buffer_from_file_view.Related: #115816
Related: #103706
Changelog category (leave one):
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122250]
Version info
26.10.1.1408-master(included in26.10and later)