1#pragma once
2#include <DataStreams/IBlockInputStream.h>
3#include <Storages/MergeTree/MergeTreeThreadSelectBlockInputProcessor.h>
4#include <Storages/MergeTree/MergeTreeData.h>
5#include <Storages/MergeTree/MarkRange.h>
6#include <Storages/MergeTree/MergeTreeBlockReadUtils.h>
7#include <Storages/SelectQueryInfo.h>
8
9namespace DB
10{
11
12
13/// Used to read data from single part with select query
14/// Cares about PREWHERE, virtual columns, indexes etc.
15/// To read data from multiple parts, Storage (MergeTree) creates multiple such objects.
16class MergeTreeSelectProcessor : public MergeTreeBaseSelectProcessor
17{
18public:
19 MergeTreeSelectProcessor(
20 const MergeTreeData & storage,
21 const MergeTreeData::DataPartPtr & owned_data_part,
22 UInt64 max_block_size_rows,
23 size_t preferred_block_size_bytes,
24 size_t preferred_max_column_in_block_size_bytes,
25 Names column_names_,
26 MarkRanges mark_ranges,
27 bool use_uncompressed_cache,
28 const PrewhereInfoPtr & prewhere_info,
29 bool check_columns,
30 size_t min_bytes_to_use_direct_io,
31 size_t max_read_buffer_size,
32 bool save_marks_in_cache,
33 const Names & virt_column_names = {},
34 size_t part_index_in_query = 0,
35 bool quiet = false);
36
37 ~MergeTreeSelectProcessor() override;
38
39 String getName() const override { return "MergeTree"; }
40
41 /// Closes readers and unlock part locks
42 void finish();
43
44protected:
45
46 bool getNewTask() override;
47
48private:
49
50 /// Used by Task
51 Names required_columns;
52 /// Names from header. Used in order to order columns in read blocks.
53 Names ordered_names;
54 NameSet column_name_set;
55
56 MergeTreeReadTaskColumns task_columns;
57
58 /// Data part will not be removed if the pointer owns it
59 MergeTreeData::DataPartPtr data_part;
60 /// Forbids to change columns list of the part during reading
61 std::shared_lock<std::shared_mutex> part_columns_lock;
62
63 /// Mark ranges we should read (in ascending order)
64 MarkRanges all_mark_ranges;
65 /// Total number of marks we should read
66 size_t total_marks_count = 0;
67 /// Value of _part_index virtual column (used only in SelectExecutor)
68 size_t part_index_in_query = 0;
69
70 bool check_columns;
71 String path;
72 bool is_first_task = true;
73
74 Logger * log = &Logger::get("MergeTreeSelectProcessor");
75};
76
77}
78