Repository navigation
Conversation
`MergeTreeBlockSizePredictor` is created with every column the reader reads (result columns plus the columns of every PREWHERE step), but on the first `update()` of a task it re-initialized itself from the result block only, to re-estimate DEFAULT/MATERIALIZED columns the part does not hold. Since ClickHouse#89982 (`query_plan_remove_unused_columns`) columns used only by PREWHERE are not in the result block, so after the first block their bytes per row dropped out of the estimate, `estimateNumRows` saturated and every later block was `max_block_size` rows of the wide columns. `preferred_block_size_bytes` was effectively ignored, which is the ~7x peak memory reported in ClickHouse#107596 (735.8 MiB vs 45.2 MiB with `query_plan_remove_unused_columns = 0` on the issue's reproducer). Keep the constructor's sample block and merge it into the re-initialization block, and keep the current estimate of a dynamic column that is absent from the result block. `block_size_bytes` still counts only the columns that are in the block. With the change the reproducer peaks at 45.1 MiB at default settings. Closes ClickHouse#107596 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; 2 findings) plus my own review (1 finding).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261015-141700 |
|
Workflow [PR], commit [7a60373] Summary: ❌
AI ReviewSummaryThe PR retains per-part size estimates for columns used only by Final Verdict✅ Approve |
|
cc @tiandiwonder @Algunenano, could you review this? On the first |
CI finish ledger - b774a99Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261015-230015 |
|
Performance Comparison (arm_release, 1/6 and 6/6) on 7a60373: both slowdowns are real and caused by this PR, and they are the intended trade-off of the fix rather than a defect.
The metrics (from So the two red performance shards should be accepted by the reviewer as the cost of honouring |
|
superseded by #122919 |
Closes: #107596
Related: #122919
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
preferred_block_size_bytesis respected again for columns that are read only byPREWHERE(including conditions moved there automatically), which brings the peak memory of such queries back to the 26.1 level. Closes #107596.Description
On 26.3.42.3, a query whose
PREWHEREreads a wide column that it does not output ignorespreferred_block_size_bytesafter the first block: with ~1000-byte rows andpreferred_block_size_bytes = 100000it reads 9872-row blocks instead of ~128. This is the 7x peak memory in #107596.MergeTreeBlockSizePredictoris created with every column the reader reads, but on the firstupdate()it re-initializes itself from the result block only. Since #89982 (query_plan_remove_unused_columns) columns used only byPREWHEREare not in the result block, so after the first block their bytes per row drop out of the estimate and blocks grow tomax_block_size.The fix keeps the constructor's columns in that re-initialization and keeps the current estimate of a column that is absent from the result block. 2 files, +18/-2. Such queries go back to their 26.1 block sizes; the per-block cost of the estimate is unchanged. Compact parts store no per-column sizes, so there these columns still count as 0 bytes; such a part is smaller than
min_bytes_for_wide_part(10 MiB by default), which bounds the block.Validation (debug build, the issue's schema and generator,
max_threads = 6, peakmemory_usage): master 735.8 MiB at defaults vs 45.2 MiB withquery_plan_remove_unused_columns = 0; with this change 45.1 MiB at defaults. The new test fails on master (both queries) and passes 50/50 with randomized settings, and in the s3, DatabaseReplicated and parallel replicas modes.#122919 addresses the same mechanism and also brings the reproducer to 45.1 MiB. This PR is a smaller variant (no new
MergeTreeReadersChainAPI, noBlockbuilt per read) and adds a regression test.Workflow [PR]
Sync PR [sync-upstream/pr/126041]