ClickHouse/src/Storages/MergeTree/MergeTreeThreadSelectProcessor.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2.5 KiB
C++
Raw Normal View History

2019-10-10 16:30:30 +00:00
#include <Storages/MergeTree/IMergeTreeReader.h>
#include <Storages/MergeTree/MergeTreeReadPool.h>
2021-07-26 16:48:25 +00:00
#include <Storages/MergeTree/MergeTreeThreadSelectProcessor.h>
#include <Interpreters/Context.h>
2016-11-20 12:43:20 +00:00
namespace DB
{
2022-11-18 20:09:20 +00:00
MergeTreeThreadSelectAlgorithm::MergeTreeThreadSelectAlgorithm(
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_,
size_t preferred_block_size_bytes_,
size_t preferred_max_column_in_block_size_bytes_,
const MergeTreeData & storage_,
const StorageSnapshotPtr & storage_snapshot_,
bool use_uncompressed_cache_,
const PrewhereInfoPtr & prewhere_info_,
const ExpressionActionsSettings & actions_settings_,
const MergeTreeReaderSettings & reader_settings_,
2023-02-03 13:34:18 +00:00
const Names & virt_column_names_)
2023-02-14 14:14:11 +00:00
: IMergeTreeSelectAlgorithm{
pool_->getHeader(), storage_, storage_snapshot_, prewhere_info_, actions_settings_, max_block_size_rows_,
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_)}
{
2023-02-03 13:34:18 +00:00
min_marks_to_read = min_marks_for_concurrent_read_;
}
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);
return static_cast<bool>(task);
}
2022-11-18 20:09:20 +00:00
void MergeTreeThreadSelectAlgorithm::finalizeNewTask()
{
const std::string part_name = task->data_part->isProjectionPart() ? task->data_part->getParentPart()->name : task->data_part->name;
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_); };
const auto & metadata_snapshot = storage_snapshot->metadata;
2022-07-17 18:41:17 +00:00
IMergeTreeReader::ValueSizeMap value_size_map;
2023-02-07 17:50:31 +00:00
if (reader && 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-07 17:50:31 +00:00
/// task->reader.valid() means there is a prefetched reader in this test, use it.
const bool init_new_readers = !reader || task->reader.valid() || part_name != last_read_part_name;
2022-07-17 18:41:17 +00:00
if (init_new_readers)
{
2023-02-07 17:50:31 +00:00
initializeMergeTreeReadersForCurrentTask(metadata_snapshot, 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;
}
2022-11-18 20:09:20 +00:00
void MergeTreeThreadSelectAlgorithm::finish()
{
reader.reset();
pre_reader_for_step.clear();
2016-11-20 12:43:20 +00:00
}
2022-11-18 20:09:20 +00:00
MergeTreeThreadSelectAlgorithm::~MergeTreeThreadSelectAlgorithm() = default;
2016-11-20 12:43:20 +00:00
}