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 MergeTreeReverseSelectProcessor : public MergeTreeBaseSelectProcessor
17{
18public:
19 MergeTreeReverseSelectProcessor(
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 ~MergeTreeReverseSelectProcessor() override;
38
39 String getName() const override { return "MergeTreeReverse"; }
40
41 /// Closes readers and unlock part locks
42 void finish();
43
44protected:
45
46 bool getNewTask() override;
47 Chunk readFromPart() override;
48
49private:
50 Block header;
51
52 /// Used by Task
53 Names required_columns;
54 /// Names from header. Used in order to order columns in read blocks.
55 Names ordered_names;
56 NameSet column_name_set;
57
58 MergeTreeReadTaskColumns task_columns;
59
60 /// Data part will not be removed if the pointer owns it
61 MergeTreeData::DataPartPtr data_part;
62 /// Forbids to change columns list of the part during reading
63 std::shared_lock<std::shared_mutex> part_columns_lock;
64
65 /// Mark ranges we should read (in ascending order)
66 MarkRanges all_mark_ranges;
67 /// Total number of marks we should read
68 size_t total_marks_count = 0;
69 /// Value of _part_index virtual column (used only in SelectExecutor)
70 size_t part_index_in_query = 0;
71
72 String path;
73
74 Chunks chunks;
75
76 Logger * log = &Logger::get("MergeTreeReverseSelectProcessor");
77};
78
79}
80