Repository navigation
Use merge_use_batch_sorting_queue for projection merges - #132085
Algunenano merged 4 commits into
Conversation
The `!global_ctx->projection` guard in `createMergedStream` kept every child `MergeTask` that merges projection parts (the projection-part merges of a parent merge and the temporary-part merges of `MergeProjectionPartsTask`) on the default sorting queue, even with `merge_use_batch_sorting_queue = 1`. It was added in ClickHouse#108468 for missing coverage, not for a defect. Normal projection merges are `Ordinary` and row-preserving; aggregate projections and children of DEDUPLICATE/CLEANUP parents still have `merge_may_reduce_rows` and keep the default queue. `_parent_part_offset` is remapped when the projection parts are read, not by the sorting algorithm. The new test compares the merged projection parts (rows and positions) between the two queues for a normal projection with another sorting key, a `_parent_part_offset` projection and a commit-order projection, in horizontal and vertical merges, asserts via part_log that the projections were merged rather than rebuilt, and covers the temporary parts that `MATERIALIZE PROJECTION` writes for a part larger than `min_insert_block_size_rows`. Related: ClickHouse#127826 Related: ClickHouse#108468 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ueue Two tables with `merge_use_batch_sorting_queue = 1` and a normal projection, ten parts each, merged with `OPTIMIZE ... DRY RUN PARTS`. The parts are disjoint in the table's sorting key, so the parent merge does the same work on master and with this change. In the first table the projection parts alternate in runs of 100 rows of the projection key, the case the batch queue serves; in the second they interleave row by row, where it cannot help. Measured locally on release builds, 32 alternating runs, PR / master medians: the runs query 0.909 (projection stage 0.850), the interleaved query 1.047 (projection stage 1.060). Runs of 1000 rows (0.911) and a second run-shaped projection (0.911) did not separate the binaries further. `optimize_dry_run_check_part = 0` keeps `checkDataPart` of the dry-run result out of the measurement. The test opts out of the Iceberg configuration with `<test iceberg="0">`: OPTIMIZE DRY RUN is only supported for MergeTree tables, and an edit of `iceberg_skip_list.txt` would run the whole Iceberg configuration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [740001e] Summary: ✅
AI ReviewSummaryReviewed commit Final VerdictStatus: ✅ Approve |
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding; bounded: 1 full pass + 1 fix round + 1 delta recheck). My own review found no code issue; it only corrected labels in the PR description.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261116-170341 |
|
cc @cwurm, could you review this? As you asked in #127826, it drops the |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261116-143800 |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 44 s compile time in total, 8 of them have a recent master baseline. |
The flaky check ran the test over 180 s in 7 of 126 runs (amd_binary 5, amd_debug 1, amd_msan 1). The slow runs are the ones whose random MergeTree settings give the 1.2M-row tables tiny granules or tiny merge blocks: with `index_granularity` or `merge_max_block_size` below ~2000, `MATERIALIZE PROJECTION` and `OPTIMIZE FINAL` on them took 100-420 s per run instead of ~30 s (CI `query_log` and `part_log` of the flaky-check jobs). Clamp `index_granularity`, `index_granularity_bytes` and `merge_max_block_size` from below with a `Random settings limits` line. The small tables pin `merge_max_block_size` themselves and have one granule per part either way. Also write the big table as one part directly, and give the batch-queue table a copy of it with `ATTACH PARTITION ... FROM`, instead of two inserts and two `OPTIMIZE FINAL`. The test now checks that the table has one part, which the temporary projection parts path needs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Algunenano
left a comment
There was a problem hiding this comment.
@groeneai The test is huge for little benefit (it doesn't even pass the threshold, even if the improvement is good). Longest perf thread in the shard.
Either minimize or drop it please. It's fine if we don't add a perf test for this case really
It is the longest test in its performance shard and its gain stays below the comparison threshold, so it guards little for its cost. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Dropped the performance test in 740001e. The PR now changes only |
|
@groeneai Thanks! Could you please also remove the remaining It came in the same commit as the projection term (#108468 (comment)), also for missing coverage, not for a defect. Only
In the horizontal cases, the merge itself is a plain sorted merge, so it should get the same gain as other ordinary merges. The batch path already handles row masks ( Only the queue condition should change. Please update the setting description and add a small, fast stateless test that compares the merged result under both queues for lightweight delete, TTL delete (horizontal and vertical each, including |
|
Acknowledged. I'm investigating removing the |
|
I opened #133262. It removes the term, rewrites the setting description and adds the test you described; the vertical cases now run the row-mask code in Merge time with the setting on / off (release, 10 overlapping parts of 1M rows, 5% of rows deleted): 0.92 for a horizontal lightweight delete merge, 0.98 for vertical lightweight delete and TTL delete merges (masked rows are still inserted one by one), and 1.04 where the keys interleave row by row. One correction to the mechanism: in horizontal merges expired TTL rows are dropped by |
Related: #127826
Related: #108468
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
With
merge_use_batch_sorting_queueenabled, merges of normal projection parts, including the temporary parts written while a projection is built, now also use the batch sorting queue. With the setting enabled, merged projection parts can be split into blocks differently than on previous versions. The data is the same, but in aReplicatedMergeTreecluster with replicas on different versions this can show up as a harmless "not byte-identical" checksum mismatch, after which the replica downloads the merged part from another replica.Description
Asked for in #127826 (comment). #108468 kept every
MergeTaskwithglobal_ctx->projectionon the default sorting queue for missing coverage (#108468 (comment)), not for a defect. Nowmerge_may_reduce_rowsalone decides, as for base tables: normal projections merge asOrdinary, row-preserving child tasks, aggregate projections and children ofDEDUPLICATE/CLEANUPmerges keep the default queue, and_parent_part_offsetis remapped while the projection parts are read, not by the sorting algorithm.Release build,
OPTIMIZE ... DRY RUN PARTSof 10 parts, medians:SELECT *projection, runs of 100 rowsProjection parts disjoint in the projection key show no gain (1.03 on / off: the default queue already moves whole chunks there); the temporary parts of
MATERIALIZE PROJECTIONin runs of 100 rows take 0.953 (on / off). Where the projection key interleaves row by row, the batch queue costs up to 6% of the projection stage.The new test compares the merged projection parts under both queues (normal,
_parent_part_offsetand commit-order projections, horizontal and vertical merges, temporary parts) and checks inpart_logthat the projections were merged, not rebuilt. With the setting forced on, 483 existing projection tests show no content difference (04812gets 159 instead of 157 marks, a granule layout change master also shows for base tables).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/132085]
Version info
26.11.1.2764-master(included in26.11and later)