ClickHouse/src/Storages/MergeTree/MergeTreeSelectProcessor.cpp

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

79 lines
3.0 KiB
C++
Raw Normal View History

2019-10-01 16:50:08 +00:00
#include <Storages/MergeTree/MergeTreeSelectProcessor.h>
#include <Storages/MergeTree/MergeTreeBaseSelectProcessor.h>
2019-10-10 16:30:30 +00:00
#include <Storages/MergeTree/IMergeTreeReader.h>
2022-09-05 16:55:00 +00:00
#include <Storages/MergeTree/LoadedMergeTreeDataPartInfoForReader.h>
#include <Interpreters/Context.h>
2016-11-20 12:43:20 +00:00
namespace DB
{
2022-11-18 20:09:20 +00:00
MergeTreeSelectAlgorithm::MergeTreeSelectAlgorithm(
2018-10-17 03:13:00 +00:00
const MergeTreeData & storage_,
const StorageSnapshotPtr & storage_snapshot_,
const MergeTreeData::DataPartPtr & owned_data_part_,
2019-02-10 16:55:12 +00:00
UInt64 max_block_size_rows_,
size_t preferred_block_size_bytes_,
size_t preferred_max_column_in_block_size_bytes_,
2019-07-19 14:56:00 +00:00
Names required_columns_,
2019-10-04 15:40:05 +00:00
MarkRanges mark_ranges_,
bool use_uncompressed_cache_,
const PrewhereInfoPtr & prewhere_info_,
const ExpressionActionsSettings & actions_settings_,
const MergeTreeReaderSettings & reader_settings_,
2023-02-03 13:34:18 +00:00
MergeTreeInOrderReadPoolParallelReplicasPtr pool_,
const Names & virt_column_names_,
2021-07-16 14:27:38 +00:00
size_t part_index_in_query_,
2023-02-03 13:34:18 +00:00
bool has_limit_below_one_block_)
2022-11-18 20:09:20 +00:00
: IMergeTreeSelectAlgorithm{
storage_snapshot_->getSampleBlockForColumns(required_columns_),
storage_, storage_snapshot_, prewhere_info_, actions_settings_, max_block_size_rows_,
2019-12-19 13:10:57 +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-10-01 16:50:08 +00:00
required_columns{std::move(required_columns_)},
2017-04-05 20:34:19 +00:00
data_part{owned_data_part_},
sample_block(storage_snapshot_->metadata->getSampleBlock()),
2019-10-04 15:40:05 +00:00
all_mark_ranges(std::move(mark_ranges_)),
2021-07-16 14:27:38 +00:00
part_index_in_query(part_index_in_query_),
has_limit_below_one_block(has_limit_below_one_block_),
2023-02-03 13:34:18 +00:00
pool(pool_),
total_rows(data_part->index_granularity.getRowsCountInRanges(all_mark_ranges))
{
2022-11-18 20:09:20 +00:00
ordered_names = header_without_const_virtual_columns.getNames();
2021-08-04 15:18:03 +00:00
}
2017-04-05 20:34:19 +00:00
2022-11-18 20:09:20 +00:00
void MergeTreeSelectAlgorithm::initializeReaders()
2021-08-04 15:18:03 +00:00
{
task_columns = getReadTaskColumns(
2022-09-05 16:55:00 +00:00
LoadedMergeTreeDataPartInfoForReader(data_part), storage_snapshot,
required_columns, virt_column_names, prewhere_info, actions_settings, reader_settings, /*with_subcolumns=*/ true);
2017-04-05 20:34:19 +00:00
2021-08-04 15:18:03 +00:00
/// Will be used to distinguish between PREWHERE and WHERE columns when applying filter
const auto & column_names = task_columns.columns.getNames();
column_name_set = NameSet{column_names.begin(), column_names.end()};
if (use_uncompressed_cache)
owned_uncompressed_cache = storage.getContext()->getUncompressedCache();
2017-04-05 20:34:19 +00:00
owned_mark_cache = storage.getContext()->getMarkCache();
2023-02-07 17:50:31 +00:00
initializeMergeTreeReadersForPart(
data_part, task_columns, storage_snapshot->getMetadataForQuery(), all_mark_ranges, {}, {});
}
2022-11-18 20:09:20 +00:00
void MergeTreeSelectAlgorithm::finish()
{
/** Close the files (before destroying the object).
* When many sources are created, but simultaneously reading only a few of them,
* buffers don't waste memory.
*/
reader.reset();
pre_reader_for_step.clear();
data_part.reset();
2016-11-20 12:43:20 +00:00
}
2022-11-18 20:09:20 +00:00
MergeTreeSelectAlgorithm::~MergeTreeSelectAlgorithm() = default;
2016-11-20 12:43:20 +00:00
}