2021-06-25 16:22:39 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeInOrderSelectProcessor.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int MEMORY_LIMIT_EXCEEDED;
|
|
|
|
}
|
|
|
|
|
2021-12-09 10:39:28 +00:00
|
|
|
bool MergeTreeInOrderSelectProcessor::getNewTaskImpl()
|
2021-06-25 16:22:39 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (all_mark_ranges.empty())
|
|
|
|
return false;
|
|
|
|
|
2021-08-04 15:18:03 +00:00
|
|
|
if (!reader)
|
|
|
|
initializeReaders();
|
2021-06-25 16:22:39 +00:00
|
|
|
|
|
|
|
MarkRanges mark_ranges_for_task;
|
2021-07-13 14:24:45 +00:00
|
|
|
/// If we need to read few rows, set one range per task to reduce number of read data.
|
|
|
|
if (has_limit_below_one_block)
|
2021-06-25 16:22:39 +00:00
|
|
|
{
|
2022-06-07 11:53:10 +00:00
|
|
|
mark_ranges_for_task = { std::move(all_mark_ranges.front()) };
|
2021-06-25 16:22:39 +00:00
|
|
|
all_mark_ranges.pop_front();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mark_ranges_for_task = std::move(all_mark_ranges);
|
|
|
|
all_mark_ranges.clear();
|
|
|
|
}
|
|
|
|
|
2021-08-04 15:18:03 +00:00
|
|
|
auto size_predictor = (preferred_block_size_bytes == 0) ? nullptr
|
|
|
|
: getSizePredictor(data_part, task_columns, sample_block);
|
|
|
|
|
2021-06-25 16:22:39 +00:00
|
|
|
task = std::make_unique<MergeTreeReadTask>(
|
2022-06-07 07:03:11 +00:00
|
|
|
data_part, mark_ranges_for_task, part_index_in_query, ordered_names, column_name_set, task_columns,
|
|
|
|
prewhere_info && prewhere_info->remove_prewhere_column,
|
|
|
|
std::move(size_predictor));
|
2021-06-25 16:22:39 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
/// Suspicion of the broken part. A part is added to the queue for verification.
|
|
|
|
if (getCurrentExceptionCode() != ErrorCodes::MEMORY_LIMIT_EXCEEDED)
|
2022-07-18 21:37:07 +00:00
|
|
|
storage.reportBrokenPart(data_part);
|
2021-06-25 16:22:39 +00:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|