1#include <Storages/MergeTree/AllMergeSelector.h>
2
3#include <cmath>
4
5
6namespace DB
7{
8
9AllMergeSelector::PartsInPartition AllMergeSelector::select(
10 const Partitions & partitions,
11 const size_t /*max_total_size_to_merge*/)
12{
13 size_t min_partition_size = 0;
14 Partitions::const_iterator best_partition;
15
16 for (auto it = partitions.begin(); it != partitions.end(); ++it)
17 {
18 if (it->size() <= 1)
19 continue;
20
21 size_t sum_size = 0;
22 for (const auto & part : *it)
23 sum_size += part.size;
24
25 if (!min_partition_size || sum_size < min_partition_size)
26 {
27 min_partition_size = sum_size;
28 best_partition = it;
29 }
30 }
31
32 if (min_partition_size)
33 return *best_partition;
34 else
35 return {};
36}
37
38}
39