2019-10-01 16:50:08 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeReverseSelectProcessor.h>
|
2019-07-18 14:41:11 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int MEMORY_LIMIT_EXCEEDED;
|
|
|
|
}
|
|
|
|
|
2021-12-09 10:39:28 +00:00
|
|
|
bool MergeTreeReverseSelectProcessor::getNewTaskImpl()
|
2019-07-18 14:41:11 +00:00
|
|
|
try
|
|
|
|
{
|
2021-06-25 16:22:39 +00:00
|
|
|
if (chunks.empty() && all_mark_ranges.empty())
|
2019-07-18 14:41:11 +00:00
|
|
|
return false;
|
|
|
|
|
2020-01-04 05:46:50 +00:00
|
|
|
/// We have some blocks to return in buffer.
|
2019-07-18 14:41:11 +00:00
|
|
|
/// Return true to continue reading, but actually don't create a task.
|
|
|
|
if (all_mark_ranges.empty())
|
|
|
|
return true;
|
|
|
|
|
2021-08-04 15:18:03 +00:00
|
|
|
if (!reader)
|
|
|
|
initializeReaders();
|
|
|
|
|
2019-07-18 14:41:11 +00:00
|
|
|
/// Read ranges from right to left.
|
|
|
|
MarkRanges mark_ranges_for_task = { all_mark_ranges.back() };
|
|
|
|
all_mark_ranges.pop_back();
|
|
|
|
|
2021-07-16 14:11:34 +00:00
|
|
|
auto size_predictor = (preferred_block_size_bytes == 0) ? nullptr
|
2021-08-02 12:03:55 +00:00
|
|
|
: getSizePredictor(data_part, task_columns, sample_block);
|
2019-07-18 14:41:11 +00:00
|
|
|
|
|
|
|
task = std::make_unique<MergeTreeReadTask>(
|
2019-07-19 14:56:00 +00:00
|
|
|
data_part, mark_ranges_for_task, part_index_in_query, ordered_names, column_name_set,
|
2022-06-07 07:03:11 +00:00
|
|
|
task_columns, prewhere_info && prewhere_info->remove_prewhere_column,
|
|
|
|
std::move(size_predictor));
|
2019-07-18 14:41:11 +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-01-31 20:47:04 +00:00
|
|
|
storage.reportBrokenPart(data_part);
|
2019-07-18 14:41:11 +00:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2022-07-17 18:41:17 +00:00
|
|
|
MergeTreeBaseSelectProcessor::BlockAndRowCount MergeTreeReverseSelectProcessor::readFromPart()
|
2019-07-18 14:41:11 +00:00
|
|
|
{
|
2022-07-17 18:41:17 +00:00
|
|
|
BlockAndRowCount res;
|
2019-07-18 14:41:11 +00:00
|
|
|
|
2019-10-01 16:50:08 +00:00
|
|
|
if (!chunks.empty())
|
2019-07-18 14:41:11 +00:00
|
|
|
{
|
2019-10-01 16:50:08 +00:00
|
|
|
res = std::move(chunks.back());
|
|
|
|
chunks.pop_back();
|
2019-07-18 14:41:11 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!task->range_reader.isInitialized())
|
|
|
|
initializeRangeReaders(*task);
|
|
|
|
|
|
|
|
while (!task->isFinished())
|
|
|
|
{
|
2022-07-17 18:41:17 +00:00
|
|
|
auto chunk = readFromPartImpl();
|
2019-10-01 16:50:08 +00:00
|
|
|
chunks.push_back(std::move(chunk));
|
2019-07-18 14:41:11 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 16:50:08 +00:00
|
|
|
if (chunks.empty())
|
2019-07-18 14:41:11 +00:00
|
|
|
return {};
|
|
|
|
|
2019-10-01 16:50:08 +00:00
|
|
|
res = std::move(chunks.back());
|
|
|
|
chunks.pop_back();
|
2019-07-18 14:41:11 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|