Repository navigation
Conversation
…ngMergeTree merges `ReplacingSortedAlgorithm::merge` and `CollapsingSortedAlgorithm::merge` built `RowRef current_row` with `setRowRef` for every input row. That copied the chunk's `SharedChunkPtr` by value into the out-of-line `RowRefWithOwnedChunk::set` (refcount up, release of the row's previous chunk, refcount down when the row dies), only to compare the row with the kept one and to read its source number. Collapsing also copied it into `last_row` at every new key, and vertical FINAL recorded every kept row number through `IColumn::insert(const Field &)`. Change the two shared helpers once instead of adding per-algorithm copies: - `RowRefWithOwnedChunk::set` is inline, takes the chunk by const reference and re-binds it only when the row points to another chunk. A held reference keeps its allocator slot alive, so an equal pointer is the same live chunk. - `IMergingAlgorithmWithSharedChunks::rowsHaveDifferentSortColumns` compares a row with a cursor (same logic: the part-level shortcut, `prev_unequal_column`, `checkEqualsFirstNonEqual` on the cursor's `sort_columns` and `getRow()`). The RowRef/RowRef form had no other caller, so the shortcut questioned in ClickHouse#120649 stays in one place for both algorithms. Replacing and Collapsing compare against the cursor and take the source number from it; Collapsing builds a RowRef only for a row with an invalid sign, which it inserts or buffers. Vertical FINAL appends the row number to its `ColumnUInt64` directly. `max_row_refs` is unchanged: the slots counted for "current" are headroom that vertical FINAL's `to_be_emitted` queue uses. Local A/B, non-LTO RelWithDebInfo, Xeon 6975P-C, 4 pinned cores, 10 paired rounds, user CPU fix/base geomean [95% CI]: rsrc50 FINAL 0.86 [0.79, 0.94], rver50 FINAL 0.84 [0.77, 0.92], rver4 FINAL 0.79 [0.74, 0.84], ccol50 FINAL 0.90 [0.87, 0.93], OPTIMIZE FINAL rver50 0.87 [0.81, 0.93]; instructions:u rsrc50 FINAL 0.78, ccol50 FINAL 0.92; plain MergeTree OPTIMIZE 0.996 (control). Adds a performance test for Replacing/Collapsing FINAL over overlapping parts (no CollapsingMergeTree FINAL perf test existed). Analysis and patches from ClickHouse#131239 by @ snelheidai. 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 (3 findings).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261114-002402 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261113-230600 |
|
Workflow [PR], commit [dbdbe0e] Summary: ✅
AI ReviewSummaryRemoves temporary owning Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units23 translation units recompiled, 116 s compile time in total, 23 of them have a recent master baseline. |
CI finish ledger - 7eb9620Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Session id: cron:our-pr-ci-monitor:20261114-043009 |
…g perf jobs
The test measures FINAL and merges of ReplacingMergeTree and
CollapsingMergeTree, and Iceberg storage does not support FINAL
("Storage IcebergLocal doesn't support FINAL"), so the six
`Performance Comparison (*, iceberg_*)` jobs that a new MergeTree test
schedules could not run any of its queries. Opt the test out with
`<test iceberg="0">` instead of an iceberg_skip_list.txt entry: that
file is in ICEBERG_PERFORMANCE_PATHS, so editing it would run the whole
Iceberg suite.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g-merge-no-per-row-rowref Conflicts resolved against master: - ClickHouse#126158 added [[nodiscard]] to lines this PR edits: kept, except on RowRefWithOwnedChunk::firstNonEqualSortColumnsWith, which this PR removes. - ClickHouse#131513 gated the part-level shortcut of rowsHaveDifferentSortColumns with nonzero_level_parts_have_unique_keys: the cursor overload keeps that gate, so CollapsingMergeTree still compares rows of merged parts. - ClickHouse#131560 counts selected rows in vertical FINAL: kept, the selection is appended with push_back instead of insert(Field). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #131239
Related: #120649
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
FINALqueries and merges ofReplacingMergeTreeandCollapsingMergeTreetables are faster:FINALover many overlapping parts uses 9-25% less CPU.Description
ReplacingSortedAlgorithm::mergeandCollapsingSortedAlgorithm::mergebuilt aRowReffor every input row only to compare it with the kept row. The out-of-lineRowRefWithOwnedChunk::settook the chunk pointer by value (a reference count increment and decrement per row), and verticalFINALrecorded each kept row throughIColumn::insert(const Field &). Analysis and patches by @ snelheidai.The change is made once, in the shared helpers:
setis inline, takes the chunk by const reference and re-binds it only when it changes, androwsHaveDifferentSortColumnscompares a row with the cursor. Collapsing builds aRowRefonly for a row with an invalid sign; verticalFINALappends the row number directly.VersionedCollapsingMergeTreequeues every row, so it keeps itsRowRefand gains only from the inlineset. The part-level shortcut questioned in #120649 is unchanged and now has one implementation.Local A/B on the issue's data (release build without ThinLTO, 4 cores, 20 paired rounds, fix/master, 95% CI):
FINAL, 50 parts, unique keysFINAL, 50 parts, version columnFINAL, 4 large partsCollapsingMergeTreeFINAL, 50 partsOPTIMIZE ... FINAL, version columnOPTIMIZE ... FINAL, plainMergeTree(control)User-space instructions of the first query drop by 22%. Output is byte-identical to master in 393 checks (both
FINALmodes, merges,CLEANUP, TTL, lightweight deletes, invalid signs, insert-time merges); two mutations of the new code break 145 and 363 of them. A new performance test covers both engines over overlapping parts.Workflow [PR]
Sync PR [sync-upstream/pr/131494]