Backport #62432 to 24.3: Fix queries with FINAL give wrong result when table does not use adaptive granularity

This commit is contained in:
robot-clickhouse 2024-05-23 10:08:26 +00:00
parent 714b1863e2
commit 9079f9cba9
3 changed files with 29 additions and 7 deletions

View File

@ -617,14 +617,11 @@ SplitPartsRangesResult splitPartsRanges(RangesInDataParts ranges_in_data_parts,
}
/// Process parts ranges with undefined value at end mark
bool is_intersecting = part_index_start_to_range.size() > 1;
/// The last parts ranges could be non-intersect only if: (1) there is only one part range left, (2) it belongs to a non-L0 part,
/// and (3) the begin value of this range is larger than the largest end value of all previous ranges. This is too complicated
/// to check, so we just add the last part ranges to the intersecting ranges.
for (const auto & [part_range_index, mark_range] : part_index_start_to_range)
{
if (is_intersecting)
add_intersecting_range(part_range_index.part_index, mark_range);
else
add_non_intersecting_range(part_range_index.part_index, mark_range);
}
add_intersecting_range(part_range_index.part_index, mark_range);
auto && non_intersecting_ranges_in_data_parts = std::move(non_intersecting_ranges_in_data_parts_builder.getCurrentRangesInDataParts());
auto && intersecting_ranges_in_data_parts = std::move(intersecting_ranges_in_data_parts_builder.getCurrentRangesInDataParts());

View File

@ -0,0 +1,2 @@
Disabled 11338881281426660955 14765404159170880511
Enabled 11338881281426660955 14765404159170880511

View File

@ -0,0 +1,23 @@
-- Tags: no-random-settings, no-random-merge-tree-settings
DROP TABLE IF EXISTS account_test;
CREATE TABLE account_test
(
`id` UInt64,
`row_ver` UInt64,
)
ENGINE = ReplacingMergeTree(row_ver)
ORDER BY id
SETTINGS index_granularity = 16, index_granularity_bytes = 0,
min_rows_for_wide_part = 0, min_bytes_for_wide_part = 0,
min_rows_for_compact_part = 0, min_bytes_for_compact_part = 0;
SYSTEM STOP MERGES account_test;
INSERT INTO account_test VALUES (11338881281426660955,717769962224129342),(12484100559155738267,7950971667203174918),(7603729260199571867,3255798127676911942),(7023543111808724827,911615979861855126),(10293135086416484571,3264379259750736572),(15561193439904316763,8419819469587131454),(17632407413882870235,7252071832370181502),(17009726455991851227,7525297506591593939),(12392078953873778779,8473049173389293961),(15283366022689446555,11692491360262171467),(9087459014730986523,2783662960221838603),(293823584550906267,4847630088179732782),(15693186194430465755,8163804880526285623),(7353080168325584795,17315892478487497859),(5980311238303466523,6943353798059390089),(14242621660019578011,8684624667957352769),(8241843507567433563,15731952080102886438);
INSERT INTO account_test VALUES (11338881281426660955, 14765404159170880511);
SELECT 'Disabled', * FROM account_test FINAL WHERE id = 11338881281426660955 SETTINGS split_parts_ranges_into_intersecting_and_non_intersecting_final = 0;
SELECT 'Enabled', * FROM account_test FINAL WHERE id = 11338881281426660955 SETTINGS split_parts_ranges_into_intersecting_and_non_intersecting_final = 1;