Repository navigation
Remove current_task_last_mark from MergeTree readers - #113584
Conversation
The parameter is redundant since commit fbacf3a, which keeps `IMergeTreeReader::all_mark_ranges` in sync with the current task's mark ranges on the reader-reuse path (`MergeTreeReadPoolBase::createTask`). At every call site the passed value was equal to `getLastMark(reader->all_mark_ranges)`, so the right bound of ranged read requests on remote disks is now derived inside the reader from its own `all_mark_ranges` (cached in the `last_mark_to_read` member). This also fixes multiplied S3 read requests when a step of the readers chain reads over fragmented mark ranges: `continueReadingChain` computed the bound from the ranges started by the current read block only, not from the whole task, so with fragmented task ranges (e.g. a skip index applied at index analysis time plus `PREWHERE`) the bound advanced on every read block, and every advance cancelled the buffer's prefetch and issued a new small read request. Patch readers are now refreshed with their per-task mark ranges on the reader-reuse path (`MergeTreeReadTask::Readers::updateAllMarkRanges`), because their right bound now also comes from their own `all_mark_ranges`. Related: ClickHouse#112296 Related: ClickHouse#112296 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [12fc5d7] Summary: ❌
AI ReviewSummaryThis PR removes the explicit Final Verdict✅ No blocking issues found. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 161/174 (92.53%) · Uncovered code |
| const auto & rows_per_granule = result.rows_per_granule; | ||
| const auto & started_ranges = result.started_ranges; | ||
|
|
||
| size_t current_task_last_mark = ReadResult::getLastMark(started_ranges); |
There was a problem hiding this comment.
This takes only the last mark of the currently started ranges, not the last mark of the whole read task.
If the read task contains, e.g., ranges [0; 8), [10; 16), on read of the second range, it could cause a call of
This causes a reset of the current read buffer and a GET request from object storage on the next read.
I think it's more correct to set the last mark as a last mark (all_mark_ranges in IMergTreeReader) of the read task, and allow ReadBuffers to decide when to start a new request in seek depending on the setting remote_read_min_bytes_for_seek.
current_task_last_mark from MergeTree readers
| /// 3. current_task_last_mark argument in readRows() (which is used only for reading from remote fs to make precise | ||
| /// ranged read requests) is different from current reader's IMergeTreeReader::all_mark_ranges.back().end because | ||
| /// the same reader can be reused between read tasks - if the new task mark ranges correspond to the same part we last | ||
| /// read, so we cannot rely on all_mark_ranges and pass actual current_task_last_mark. But here we can do prefetch for begin | ||
| /// of range only once so there is no such problem. |
There was a problem hiding this comment.
This comment is outdated, because all_mark_ranges are always updated in updateAllMarkRanges when we reuse the reader between read tasks.
The 600000-row INSERT with index_granularity = 16 and 512-byte compression blocks on `s3_disk` timed out on sanitizer builds in the flaky check. Shrink the dataset 10x and lower `max_block_size` to 64 to keep the number of read blocks (and therefore the number of read requests issued by the broken code) high: measured 99 vs 7 requests with the assertion threshold of 20. Also pin `enable_parallel_replicas = 0` in the EXPLAIN query: with parallel replicas forced by the ParallelReplicas jobs, the local plan is embedded into a boxed subplan and the `Granules:` line gets a border prefix, which broke the reference. CI report: ClickHouse#113584 Co-Authored-By: Claude Fable 5 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This is a read-path refactor: it caches the last mark to read and bounds remote-filesystem ranged read requests for fragmented mark ranges (PREWHERE plus skip indexes), leaving the query-execution compute path untouched. Both flagged queries (Q28, Q32) are already not_sure from mixed test signals, and CPU time is essentially flat for both (15297 vs 15420 ms, 18447 vs 18397 ms), so the ~6% wall-clock moves read as I/O run-to-run variance rather than a compute regression. No consistent directional signal here; nothing to act on. 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
|
a7cd483
Test `04812_prewhere_fragmented_ranges_s3_read_requests` now runs the same `PREWHERE` query twice: with the mark ranges of a read task fragmented by index analysis, and with them fragmented by the ranges refiner in read pools (`use_indexes_refiner_in_read_pools`). Both cases assert that the number of S3 read requests stays low; the refiner case also asserts that the refiner did drop marks, so it cannot silently degrade into the analysis path. Checked against the release build of the last commit without the fix for read fragmentation (`2de0d16b63b`): the analysis case issues 99 S3 read requests and the refiner case 189 (with 3375 marks dropped by the refiner), versus 7 and 3 with the fix. Test `04654_skip_indexes_refiner_remote_disk` is removed. It asserted the shrink-only refinement of ranges of parts on remote disks, which was dropped in `c8fcfdd09cc` because the right bound of ranged read requests now spans the whole read task. Build report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112296&sha=2de0d16b63bf36975d10da3068a0d9fc025c7825&name_0=PR&name_1=Build+%28amd_release%29 Related: ClickHouse#112296 Related: ClickHouse#113584 Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed multiplied read requests on remote disks when a step of the readers chain reads over fragmented mark ranges, e.g., ranges filtered by primary or skip indexes.
Version info
26.8.1.976(included in26.8and later)