Repository navigation
MergeTree FINAL to not compare rows from same non-L0 part - #58142
Conversation
Signed-off-by: Duc Canh Le <[email protected]>
|
This is an automated comment for commit 91a87d6 with description of existing statuses. It's updated for the latest CI running ✅ Click here to open a full report in a separate page Successful checks
|
It should be under setting, because it's possible to get some parts with _0 level with duplicates in ReplacingMergeTree (ATTACH PART, insert with optimize_on_insert=0) |
|
@UnamedRus By non-L0 parts I mean this optimization only applies to streams with part level > 0 |
|
My mistake then. |
|
Funnily i made the same mistake while reading @canhld94 proposal but i think the assumption indeeds holds for level > 0, as there is no other source for level increase than merge as far as i know. But maybe we miss some corner cases. |
|
We have another optimization, which rely on that assumption for level > 0 #19375, |
| size_t num_columns = 0; | ||
| UInt64 row_num = 0; | ||
|
|
||
| int source_stream_index = -1; |
There was a problem hiding this comment.
Yes, I think we can just use UInt64, because when hasEqualSortColumnsWith is called the object surely has been initialised.
alexey-milovidov
left a comment
There was a problem hiding this comment.
The idea is good, but a few changes are needed.
Signed-off-by: Duc Canh Le <[email protected]>
Signed-off-by: Duc Canh Le <[email protected]>
Signed-off-by: Duc Canh Le <[email protected]>
|
I update the implementation, for each chunk |
…te row of one key from a merged part `IMergingAlgorithmWithSharedChunks::rowsHaveDifferentSortColumns` skipped the key comparison for two rows of one source whose part level is non-zero (added by ClickHouse#58142 in 24.1), on the premise that a merged part holds one row per sort key. That holds for ReplacingMergeTree, but a CollapsingMergeTree merge keeps the first cancel row and the last state row of a key when their counts are equal and the last row is a state row. When such a part was the oldest source of a key in a later merge or FINAL, the pair was split into two key groups: the group head (the cancel row) was collapsed on its own. A merge then kept the stale cancel row next to the newer state row (`sum(sign)` 1 -> 0, written to disk), and FINAL could return a row of an object whose rows all cancel. The shortcut is now opt-in per algorithm: `ReplacingSortedAlgorithm` sets `nonzero_level_parts_have_unique_keys`, so `CollapsingSortedAlgorithm` compares the sort columns of every pair of rows again (the 23.8 behaviour) in merges, vertical merges and FINAL. Summing, Aggregating and Coalescing use `IMergingAlgorithmWithDelayedChunk` and keep one row per key, so their shortcut is unchanged; VersionedCollapsing compares keys directly. Parts already written by affected versions are not repaired. Closes ClickHouse#120649 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Currently, merging FINAL comparing current row to next row in sorting queue to check if the key has changed. It means total number of comparisons == number of read rows.
However, if two rows are from same non-L0 part, their keys must be distinct, and we can skip comparing them. This optimisation can significantly reduce number of comparisons in some case, e.g. we read from one big part and and some other small parts.
It means to complement #54366 but I create a new PR because this optimisation will apply to any non-ordinary merge tree.
It can also complement #58120 in case where parts have intersect ranges but almost no intersect rows.
Documentation entry for user-facing changes