ClickHouse/src/Storages/MergeTree/MergeTreeThreadSelectProcessor.cpp

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

85 lines
2.7 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_,
2021-06-25 14:49:28 +00:00
ExpressionActionsSettings actions_settings,
const MergeTreeReaderSettings & reader_settings_,
2023-02-03 13:34:18 +00:00
const Names & virt_column_names_)
:
2022-11-18 20:09:20 +00:00
IMergeTreeSelectAlgorithm{
pool_->getHeader(), storage_, storage_snapshot_, prewhere_info_, std::move(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;
2016-11-20 12:43:20 +00:00
if (!reader)
{
if (use_uncompressed_cache)
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;
}
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
}