2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/MergeTree/AllMergeSelector.h>
|
2016-10-30 08:15:55 +00:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-09-03 13:29:18 +00:00
|
|
|
AllMergeSelector::PartsRange AllMergeSelector::select(
|
|
|
|
const PartsRanges & parts_ranges,
|
2017-12-01 21:13:25 +00:00
|
|
|
const size_t /*max_total_size_to_merge*/)
|
2016-10-30 08:15:55 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t min_partition_size = 0;
|
2020-09-03 13:29:18 +00:00
|
|
|
PartsRanges::const_iterator best_partition;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-09-03 13:29:18 +00:00
|
|
|
for (auto it = parts_ranges.begin(); it != parts_ranges.end(); ++it)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
if (it->size() <= 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
size_t sum_size = 0;
|
|
|
|
for (const auto & part : *it)
|
|
|
|
sum_size += part.size;
|
|
|
|
|
|
|
|
if (!min_partition_size || sum_size < min_partition_size)
|
|
|
|
{
|
|
|
|
min_partition_size = sum_size;
|
|
|
|
best_partition = it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_partition_size)
|
|
|
|
return *best_partition;
|
|
|
|
else
|
|
|
|
return {};
|
2016-10-30 08:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|