dbms: Server: queries with several replicas: development [#METR-14410]

This commit is contained in:
Alexey Arno 2015-01-22 17:22:59 +03:00
parent fd4cfb2b2e
commit f618f02d23

View File

@ -237,21 +237,13 @@ BlockInputStreams MergeTreeDataSelectExecutor::read(
RangesInDataParts parts_with_ranges;
/// Найдем, какой диапазон читать из каждого куска.
size_t sum_marks = 0;
size_t sum_ranges = 0;
for (auto & part : parts)
{
RangesInDataPart ranges(part, (*part_index)++);
ranges.ranges = markRangesFromPkRange(part->index, key_condition);
if (!ranges.ranges.empty())
{
parts_with_ranges.push_back(ranges);
sum_ranges += ranges.ranges.size();
for (const auto & range : ranges.ranges)
sum_marks += range.end - range.begin;
}
}
if (settings.parallel_replicas_count > 1)
@ -260,8 +252,9 @@ BlockInputStreams MergeTreeDataSelectExecutor::read(
settings.parallel_replicas_count);
auto segments = splitter.perform();
if (settings.parallel_replica_offset < segments.size())
{
if (settings.parallel_replica_offset >= segments.size())
return BlockInputStreams();
if (segments.size() > 1)
{
/// Для каждого элемента массива segments, вычисляем его хэш
@ -278,14 +271,18 @@ BlockInputStreams MergeTreeDataSelectExecutor::read(
hashed_segments.push_back(entry);
}
std::sort(hashed_segments.begin(), hashed_segments.end(), [&](const Entry & lhs, const Entry & rhs)
std::sort(hashed_segments.begin(), hashed_segments.end(), [](const Entry & lhs, const Entry & rhs)
{
return lhs.first < rhs.first;
});
parts_with_ranges = std::move(*(hashed_segments[settings.parallel_replica_offset].second));
}
}
/// Пересчитываем количество засечек и диапазонов.
/// Считаем количество засечек и диапазонов.
size_t sum_marks = 0;
size_t sum_ranges = 0;
sum_marks = 0;
sum_ranges = 0;
for (const auto & part_with_ranges : parts_with_ranges)
@ -294,14 +291,6 @@ BlockInputStreams MergeTreeDataSelectExecutor::read(
for (const auto & range : part_with_ranges.ranges)
sum_marks += range.end - range.begin;
}
}
}
else
{
BlockInputStreams res;
return res;
}
}
LOG_DEBUG(log, "Selected " << parts.size() << " parts by date, " << parts_with_ranges.size() << " parts by key, "
<< sum_marks << " marks to read from " << sum_ranges << " ranges");