Repository navigation
Conversation
…e mapping clickhouse-local reads local files through mmap (storage_file_read_method = 'mmap'), and the Parquet Prefetcher copied every byte range out of the mapping with readBigAt. Warm, that is an extra copy of every column chunk plus page faults on the new buffer. Cold, the copy's page faults drive the I/O and each fault reads the whole read-ahead window around the page, so small column chunks cost many times their size. MMapReadBufferFromFileDescriptor now implements readBigAtRetainCells: a single region pointing into the mapping, with an empty handle, which the Prefetcher already consumes for the userspace page cache. Before returning it asks the kernel to read exactly that range (posix_fadvise WILLNEED, best effort). readBigAt issues the same hint when the first page of the range is not cached, which covers footers and the ranges that are still copied. Decoders read up to PADDING_FOR_SIMD bytes before and after a range, so the Prefetcher keeps copying ranges that are closer than that to either end of the file. It also checks that the returned regions cover the whole range and throws the same "Unexpected eof" as readSync otherwise, instead of a debug-only assertion. A new ParquetPrefetcherReadZeroCopy profile event counts the reads that reference the read buffer's data instead of copying it. The new test checks it and compares mmap and pread reads in clickhouse-local; server tests never use mmap for files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge the two-line zero-copy comment in Prefetcher::runTask into one line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 rounds) plus my own review (2 blockers, 3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261008-051100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261008-004400 |
|
Workflow [PR], commit [d3d89cc] Summary: ❌
AI ReviewSummaryThis PR lets Findings
Tests
Final Verdict |
Build profile diff (arm_release)Commit See the job log for details. |
One POSIX_FADV_WILLNEED makes Linux read at most max(read_ahead_kb, max_sectors_kb) of the range (force_page_cache_ra() caps the request), so with the default 128 KiB the rest of a large column chunk was still read one 128 KiB page fault at a time. On an EBS volume (read_ahead_kb 128, max_sectors_kb 128) one hint for 8 MiB made 128 KiB resident; the same range advised in 128 KiB pieces became fully resident. Advise in 128 KiB pieces where the whole range is read: copies (such as footer reads) and prefetch tasks whose ranges are all decoded in full. Data pages that a later PREWHERE step, a read of selected rows or column index pruning may decode only in part keep the single hint: advising those in full made ClickBench q24 read 32% more and run 1.34x slower. 100-file ClickBench on EBS, data not cached, against the previous commit: q3 0.90, q4 0.90, q24 0.95, q30 0.85; q2, q11 unchanged. Cached hits.parquet: unchanged (q1, q2, q4, q21, q22, q23, q24, q39). Analysis and patch by snelheidai in ClickHouse#124517. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Parquet decoders may read up to PADDING_FOR_SIMD bytes on both sides of a range (Decoding.h makeDecoder). A userspace page cache cell is allocated with exactly its size, so a retained region that starts or ends at a cell edge has no readable bytes on that side, and decoding it in place could read outside the cell. The previous check only covered the two ends of the file, which is the whole condition for a memory-mapped file. Producers now report how many bytes are readable around each region, and the Prefetcher copies a single region that lacks the padding, as it already copies a range that spans several cells. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`readBigAtRetainCells` of the mmap buffer always advised the whole range once, so a range the Prefetcher had already advised in pieces (one that is decoded in full) got a second, redundant `POSIX_FADV_WILLNEED`. The caller now picks the mode: `adviseWillNeed` advises in pieces or once, and `readBigAtRetainCells` issues no hint. The pages the second hint covered were already queued by the pieces, so the I/O is the same. The hint is issued after the zero-copy decision, which reads nothing from the mapping, so a range that is copied for lack of padding (the first column chunk of a file starts at offset 4) is advised in pieces even when it may be decoded only in part: the copy reads all of it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
One range that may be decoded only in part made its whole task advised with a single hint, so a large range decoded in full that had a short partial neighbour coalesced into its task was mostly faulted in synchronously. A task covers one range plus neighbours of at most `bytes_per_read_task` (32 KiB for local files) on each side, so taking the mode of most of the task's bytes mis-advises at most those neighbours. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
📊 Cloud Performance Report 🟢 AI verdict: One query is flagged: clickbench Q20 improved by -42.3% (median 220 ms to 127 ms), and CPU time fell from about 2900 ms to 1528 ms. The shift is large and clear, so the hard-trust rule locks the verdict and it stays an improvement. The diff only touches the Parquet prefetcher's zero-copy path for memory-mapped files and the userspace page cache, plus page-cache read-ahead hints for mmap reads. If clickbench reads MergeTree tables through the server's default read method, that path is not exercised, so this PR may not be the cause. Re-run against the exact merge base before claiming the gain; the PR build reports version 26.10.1.1 and the baseline 26.10.1.42151, so the two may not share a base commit. clickbench🟢 1 improved Flagged queries (1 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
|
| || std::any_of(row_group.columns.begin(), row_group.columns.end(), [](const ColumnChunk & c) { return c.use_column_index; }); | ||
| for (size_t i = 0; i < primitive_columns.size(); ++i) | ||
| if (rows_may_be_narrowed || primitive_columns[i].first_step_to_calculate != first_step) | ||
| prefetcher.markMayBeReadPartially(row_group.columns.at(i).data_pages_prefetch); |
There was a problem hiding this comment.
This only tags the original column.data_pages_prefetch handle. In the offset-index path determinePagesToPrefetch later replaces that handle with page-sized children from splitRange, and those fresh RequestStates start with may_be_read_partially = false. So the child tasks still look "read entirely" and take the piecewise POSIX_FADV_WILLNEED path even for page-pruned / rows_to_read / later-step reads — exactly the case the single-hint policy is trying to protect.
Can we either propagate may_be_read_partially through splitRange or re-mark the child page handles after the split (excluding the undeclared dictionary-page handle if needed)?
…zero-copy Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Resolved non-zero-copy branch in
|
| Query | B, ms | M, ms | M/B [95% CI] | Page faults, M/B | Max RSS, MiB, B → M |
|---|---|---|---|---|---|
| Q24 | 181 | 139 | 0.780 [0.735, 0.827] | 0.44 | 958 → 581 |
| Q22 | 544 | 448 | 0.828 [0.807, 0.849] | 0.25 | 2834 → 1103 |
| Q21 | 486 | 411 | 0.833 [0.803, 0.864] | 0.27 | 2499 → 1052 |
| Q23 | 779 | 668 | 0.856 [0.839, 0.873] | 0.26 | 3879 → 1470 |
| Q28 | 593 | 545 | 0.910 [0.873, 0.948] | 0.74 | 3710 → 2755 |
| Q13 | 238 | 231 | 0.976 [0.960, 0.992] | 0.94 | 1823 → 1697 |
Q1, Q2, Q20 and Q37–Q40 show no significant difference; every interval contains 1.
Page cache dropped before every run (binary kept cached), 2 rounds, query time in seconds:
| Query | B | M |
|---|---|---|
| Q2 | 0.367, 0.363 | 0.053, 0.051 |
| Q37 | 0.495, 0.484 | 0.255, 0.263 |
| Q24 | 7.16, 7.17 | 4.17, 4.23 |
| Q21 | 20.89, 20.78 | 20.12, 20.12 |
Q21 is limited by reading the URL column from disk in both builds.
Closes: #124517
Related: #100300
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
clickhouse-localdecodes Parquet files directly from the memory-mapped file instead of copying every column chunk first, and asks the kernel in advance to read the byte ranges it is going to decode. Queries on Parquet files that are not in the page cache are up to 2.7 times faster and read much less from disk.Description
clickhouse-localreads files throughmmap, and the ParquetPrefetchercopied every byte range out of the mapping. Cold, each page fault of the copy reads the whole read-ahead window around the page: ClickBench q2 on 100 files read 1.96 GB from disk (6 MiB read-ahead) for 9 MB of ranges.MMapReadBufferFromFileDescriptornow implementsreadBigAtRetainCells, returning a region inside the mapping like the userspace page cache (#100300), and thePrefetcheradvises each range withPOSIX_FADV_WILLNEEDbefore decoding it. One hint makes Linux read at mostmax(read_ahead_kb, max_sectors_kb)of a range (128 KiB on EBS), so ranges decoded in full and copies are advised in 128 KiB pieces, as proposed in #124517. Data pages that later PREWHERE steps, column index pruning or lazy materialization may decode only in part keep one hint: advising them in full made q24 1.34x slower.Decoders read up to
PADDING_FOR_SIMDbytes outside a range, so producers now report the readable bytes around each region, and a region without that padding (near a file end, or at a page cache cell edge, unchecked since #100300) is copied. Short regions throw.Release build,
max_threads = 8, paired runs, fix/base:read_ahead_kb6144): q2 0.39, q3 0.38, q7 0.37, q8 0.44, q30 0.45, q36 0.70, q39 0.72.read_ahead_kb128): q3 0.58, q4 0.82, q24 0.68, q30 0.68, of which the piecewise hints give 0.85-0.95.hits.parquet, cached: q39 0.88, q37 0.95, q1 0.96, others unchanged; max RSS of q24 4.4 -> 2.7 GB. q21 (URL LIKE '%google%') is bimodal, 1.36x slower on average, from zero-copy itself (it uses 12% less CPU). The piecewise hints slow no cached query.tests/performancecannot usemmap(clickhouse-server refuses it for files), so the new stateless test comparesmmapwithpreadinclickhouse-localand checks the newParquetPrefetcherReadZeroCopyevent.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124552]