Repository navigation
Conversation
…k_size_bytes A compact part has no sizes of individual columns, and the block size predictor is built from empty sample columns, so a column of variable size was estimated at 0 bytes per row until the first block was read. The first block of every read task then had max_block_size rows regardless of preferred_block_size_bytes. Since ClickHouse#124553 a basic Map is read whole there instead of as key subcolumns, which made map_subcolumns_prewhere ClickHouse#1 and ClickHouse#3 about 30% slower on compact parts and raised their peak memory. For a compact part with more rows than max_block_size and a task without pre-read steps (PREWHERE, row policy, lightweight delete, on-the-fly mutation, index read), the pool now passes the uncompressed size of the part per row (getBytesUncompressedOnDisk, the same whole-part charge the columns cache estimate uses). The predictor raises bytes_per_row_current to it once, when a whole column of variable size is read. The first update re-initializes the estimate from the measured block as before; if the first read is filtered out entirely and never reaches update, the next startBlock restores the estimate without the floor, so filtering readers that are not pre-read steps (MergeTreeReaderIndex) keep the old behaviour from the second read on. The size is computed in the pool from the concrete part because the predictor must stay on the reader abstraction. Parts with at most max_block_size rows are read in one block per task either way and are left alone, as are wide parts, PREWHERE reads and reads of subcolumns only. Reported and first measured by snelheidai on ClickHouse#124553. 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; 1 finding), plus my own review of the code and the description.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261117-180700 |
|
cc @CheSema, could you review this? A compact part has no per-column sizes, so the first block of every read task had max_block_size rows; for a large compact part read without PREWHERE, the pool now passes the part's uncompressed size per row as the predictor's first-block estimate. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261117-145300 |
|
Workflow [PR], commit [d666316] Summary: ✅
AI ReviewSummaryReviewed commit Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units14 translation units recompiled, 110 s compile time in total, 14 of them have a recent master baseline. |
Related: #124553
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A read without
PREWHEREfrom a compact part with more rows thanmax_block_sizenow sizes its first block bypreferred_block_size_byteswhen it reads a column of variable size such asString,ArrayorMap, instead of always readingmax_block_sizerows. This lowers the peak memory and the time of such reads.Description
Since #124553, queries 1 and 3 of the
map_subcolumns_prewhereperformance test (compact part) are about 30% slower on master (CI history: 0.34 -> 0.46 s and 0.35 -> 0.44 s, peak memory 264 -> 456 MB), as measured by @ snelheidai on #124553.Root cause: a compact part has no sizes of individual columns, and the block size predictor is built from empty sample columns, so it estimates every column of variable size at 0 bytes per row until the first block is read. The first block of every read task therefore has
max_block_sizerows. Since #124553 the wholeMapis read there instead of 16 key subcolumns.Change: for a compact part with more rows than
max_block_size, read withoutPREWHERE, row policy or lightweight-delete steps, the pool passes the uncompressed size of the part per row, and the predictor uses it as the minimum estimate of the first block only. Wide parts, smaller parts and subcolumn-only reads are unchanged. So arePREWHEREreads, query 5 included: there theMapis read only byPREWHERE, and the predictor never measures such columns (a different mechanism).Validation: the new test fails on master (first block of 8192 rows) and passes with the fix, 50/50 with randomized settings. Release build, ratio = PR / master, 60 runs per side: query 1 0.72 and query 3 0.71 (peak memory 1350 -> 206 MB and 1247 -> 140 MB), wide and
PREWHEREqueries within noise, and a narrow read of oneStringout of 30 over 100 compact parts of 100000 rows 0.98 (1 thread) and 0.96 (32 threads).SELECT *of a 10M-row compact part: 0.57-0.81 over four 15-run comparisons.Whether the part-size estimate is acceptable for all such reads is the MergeTree owner's call.
Workflow [PR]
Sync PR [sync-upstream/pr/132445]