2019-10-10 16:30:30 +00:00
|
|
|
#include <Storages/MergeTree/IMergeTreeReader.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeReadPool.h>
|
2021-07-26 16:48:25 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeThreadSelectProcessor.h>
|
2020-05-20 20:16:32 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2016-11-20 12:43:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-11-18 20:09:20 +00:00
|
|
|
MergeTreeThreadSelectAlgorithm::MergeTreeThreadSelectAlgorithm(
|
2022-03-13 12:23:51 +00:00
|
|
|
size_t thread_,
|
2023-02-03 13:34:18 +00:00
|
|
|
IMergeTreeReadPoolPtr pool_,
|
|
|
|
size_t min_marks_for_concurrent_read_,
|
|
|
|
size_t max_block_size_rows_,
|
2019-01-07 10:40:58 +00:00
|
|
|
size_t preferred_block_size_bytes_,
|
|
|
|
size_t preferred_max_column_in_block_size_bytes_,
|
|
|
|
const MergeTreeData & storage_,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot_,
|
2022-03-13 12:23:51 +00:00
|
|
|
bool use_uncompressed_cache_,
|
2019-01-07 10:40:58 +00:00
|
|
|
const PrewhereInfoPtr & prewhere_info_,
|
2021-06-25 14:49:28 +00:00
|
|
|
ExpressionActionsSettings actions_settings,
|
2019-12-18 15:54:45 +00:00
|
|
|
const MergeTreeReaderSettings & reader_settings_,
|
2023-02-03 13:34:18 +00:00
|
|
|
const Names & virt_column_names_)
|
2017-03-24 13:52:50 +00:00
|
|
|
:
|
2022-11-18 20:09:20 +00:00
|
|
|
IMergeTreeSelectAlgorithm{
|
2022-06-07 11:53:10 +00:00
|
|
|
pool_->getHeader(), storage_, storage_snapshot_, prewhere_info_, std::move(actions_settings), max_block_size_rows_,
|
2020-01-04 05:46:50 +00:00
|
|
|
preferred_block_size_bytes_, preferred_max_column_in_block_size_bytes_,
|
2023-02-03 13:34:18 +00:00
|
|
|
reader_settings_, use_uncompressed_cache_, virt_column_names_},
|
2019-08-03 11:02:40 +00:00
|
|
|
thread{thread_},
|
2023-02-03 13:34:18 +00:00
|
|
|
pool{std::move(pool_)}
|
2017-03-24 13:52:50 +00:00
|
|
|
{
|
2023-02-03 13:34:18 +00:00
|
|
|
min_marks_to_read = min_marks_for_concurrent_read_;
|
2017-03-24 13:52:50 +00:00
|
|
|
}
|
2016-11-20 12:43:20 +00:00
|
|
|
|
|
|
|
/// Requests read task from MergeTreeReadPool and signals whether it got one
|
2022-11-18 20:09:20 +00:00
|
|
|
bool MergeTreeThreadSelectAlgorithm::getNewTaskImpl()
|
2016-11-20 12:43:20 +00:00
|
|
|
{
|
2023-02-03 13:34:18 +00:00
|
|
|
task = pool->getTask(thread);
|
2021-12-09 10:39:28 +00:00
|
|
|
return static_cast<bool>(task);
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
|
2022-11-18 20:09:20 +00:00
|
|
|
void MergeTreeThreadSelectAlgorithm::finalizeNewTask()
|
2021-12-09 10:39:28 +00:00
|
|
|
{
|
2021-02-10 14:12:49 +00:00
|
|
|
const std::string part_name = task->data_part->isProjectionPart() ? task->data_part->getParentPart()->name : task->data_part->name;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-03-13 18:01:46 +00:00
|
|
|
/// Allows pool to reduce number of threads in case of too slow reads.
|
2019-08-03 11:02:40 +00:00
|
|
|
auto profile_callback = [this](ReadBufferFromFileBase::ProfileInfo info_) { pool->profileFeedback(info_); };
|
2021-07-09 03:15:41 +00:00
|
|
|
const auto & metadata_snapshot = storage_snapshot->metadata;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2022-07-17 18:41:17 +00:00
|
|
|
IMergeTreeReader::ValueSizeMap value_size_map;
|
|
|
|
|
2016-11-20 12:43:20 +00:00
|
|
|
if (!reader)
|
|
|
|
{
|
|
|
|
if (use_uncompressed_cache)
|
2021-04-10 23:33:54 +00:00
|
|
|
owned_uncompressed_cache = storage.getContext()->getUncompressedCache();
|
|
|
|
owned_mark_cache = storage.getContext()->getMarkCache();
|
2016-11-20 12:43:20 +00:00
|
|
|
}
|
2023-02-03 13:34:18 +00:00
|
|
|
else if (part_name != last_read_part_name)
|
2016-11-20 12:43:20 +00:00
|
|
|
{
|
2022-07-17 18:41:17 +00:00
|
|
|
value_size_map = reader->getAvgValueSizeHints();
|
|
|
|
}
|
|
|
|
|
2023-02-03 13:34:18 +00:00
|
|
|
const bool init_new_readers = !reader || part_name != last_read_part_name;
|
2022-07-17 18:41:17 +00:00
|
|
|
if (init_new_readers)
|
|
|
|
{
|
|
|
|
initializeMergeTreeReadersForPart(task->data_part, task->task_columns, metadata_snapshot,
|
|
|
|
task->mark_ranges, value_size_map, profile_callback);
|
2016-11-20 12:43:20 +00:00
|
|
|
}
|
2019-10-10 16:30:30 +00:00
|
|
|
|
2023-02-03 13:34:18 +00:00
|
|
|
last_read_part_name = part_name;
|
2021-12-09 10:39:28 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-12-09 10:39:28 +00:00
|
|
|
|
2022-11-18 20:09:20 +00:00
|
|
|
void MergeTreeThreadSelectAlgorithm::finish()
|
2021-12-09 10:39:28 +00:00
|
|
|
{
|
|
|
|
reader.reset();
|
2022-06-07 07:03:11 +00:00
|
|
|
pre_reader_for_step.clear();
|
2016-11-20 12:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-18 20:09:20 +00:00
|
|
|
MergeTreeThreadSelectAlgorithm::~MergeTreeThreadSelectAlgorithm() = default;
|
2017-03-24 13:52:50 +00:00
|
|
|
|
2016-11-20 12:43:20 +00:00
|
|
|
}
|