mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-19 16:20:50 +00:00
Fix min_marks_to_read overflow
This commit is contained in:
parent
62e45a4c8f
commit
1a8f45464c
@ -103,8 +103,16 @@ size_t MergeTreeIndexGranularity::countMarksForRows(size_t from_mark, size_t num
|
||||
|
||||
/// This is a heuristic to respect min_marks_to_read which is ignored by MergeTreeReadPool in case of remote disk.
|
||||
/// See comment in IMergeTreeSelectAlgorithm.
|
||||
if (min_marks_to_read && from_mark + 2 * min_marks_to_read <= to_mark)
|
||||
if (min_marks_to_read)
|
||||
{
|
||||
// check that ...
|
||||
bool overflow = ((1ULL << 63) & min_marks_to_read); // further multiplication by 2 will not overflow
|
||||
if (!overflow)
|
||||
overflow = (std::numeric_limits<size_t>::max() - from_mark) < 2 * min_marks_to_read; // further addition will not overflow
|
||||
|
||||
if (!overflow && from_mark + 2 * min_marks_to_read <= to_mark)
|
||||
to_mark = from_mark + min_marks_to_read;
|
||||
}
|
||||
|
||||
return getRowsCountInRange(from_mark, std::max(1UL, to_mark)) - offset_in_rows;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user