1#pragma once
2
3#include <DataStreams/IBlockInputStream.h>
4#include <Storages/MergeTree/MergeTreeBlockReadUtils.h>
5#include <Storages/MergeTree/MergeTreeData.h>
6#include <Storages/SelectQueryInfo.h>
7
8#include <Processors/Sources/SourceWithProgress.h>
9
10namespace DB
11{
12
13class MergeTreeReader;
14class UncompressedCache;
15class MarkCache;
16
17
18/// Base class for MergeTreeThreadSelectProcessor and MergeTreeSelectProcessor
19class MergeTreeBaseSelectProcessor : public SourceWithProgress
20{
21public:
22 MergeTreeBaseSelectProcessor(
23 Block header,
24 const MergeTreeData & storage_,
25 const PrewhereInfoPtr & prewhere_info_,
26 UInt64 max_block_size_rows_,
27 UInt64 preferred_block_size_bytes_,
28 UInt64 preferred_max_column_in_block_size_bytes_,
29 UInt64 min_bytes_to_use_direct_io_,
30 UInt64 max_read_buffer_size_,
31 bool use_uncompressed_cache_,
32 bool save_marks_in_cache_ = true,
33 const Names & virt_column_names_ = {});
34
35 ~MergeTreeBaseSelectProcessor() override;
36
37 static void executePrewhereActions(Block & block, const PrewhereInfoPtr & prewhere_info);
38
39protected:
40 Chunk generate() final;
41
42 /// Creates new this->task, and initializes readers.
43 virtual bool getNewTask() = 0;
44
45 virtual Chunk readFromPart();
46
47 Chunk readFromPartImpl();
48
49 /// Two versions for header and chunk.
50 static void injectVirtualColumns(Block & block, MergeTreeReadTask * task, const Names & virtual_columns);
51 static void injectVirtualColumns(Chunk & chunk, MergeTreeReadTask * task, const Names & virtual_columns);
52
53 static Block getHeader(Block block, const PrewhereInfoPtr & prewhere_info, const Names & virtual_columns);
54
55 void initializeRangeReaders(MergeTreeReadTask & task);
56
57protected:
58 const MergeTreeData & storage;
59
60 PrewhereInfoPtr prewhere_info;
61
62 UInt64 max_block_size_rows;
63 UInt64 preferred_block_size_bytes;
64 UInt64 preferred_max_column_in_block_size_bytes;
65
66 UInt64 min_bytes_to_use_direct_io;
67 UInt64 max_read_buffer_size;
68
69 bool use_uncompressed_cache;
70 bool save_marks_in_cache;
71
72 Names virt_column_names;
73 /// This header is used for chunks from readFromPart().
74 Block header_without_virtual_columns;
75
76 std::unique_ptr<MergeTreeReadTask> task;
77
78 std::shared_ptr<UncompressedCache> owned_uncompressed_cache;
79 std::shared_ptr<MarkCache> owned_mark_cache;
80
81 using MergeTreeReaderPtr = std::unique_ptr<MergeTreeReader>;
82 MergeTreeReaderPtr reader;
83 MergeTreeReaderPtr pre_reader;
84};
85
86}
87