1 | #pragma once |
2 | |
3 | #include <Storages/MergeTree/MergeTreeIndices.h> |
4 | #include <Storages/MergeTree/MergeTreeData.h> |
5 | #include <Storages/MergeTree/KeyCondition.h> |
6 | |
7 | #include <memory> |
8 | |
9 | |
10 | namespace DB |
11 | { |
12 | |
13 | class MergeTreeIndexMinMax; |
14 | |
15 | |
16 | struct MergeTreeIndexGranuleMinMax : public IMergeTreeIndexGranule |
17 | { |
18 | explicit MergeTreeIndexGranuleMinMax(const MergeTreeIndexMinMax & index_); |
19 | MergeTreeIndexGranuleMinMax(const MergeTreeIndexMinMax & index_, std::vector<Range> && parallelogram_); |
20 | ~MergeTreeIndexGranuleMinMax() override = default; |
21 | |
22 | void serializeBinary(WriteBuffer & ostr) const override; |
23 | void deserializeBinary(ReadBuffer & istr) override; |
24 | |
25 | bool empty() const override { return parallelogram.empty(); } |
26 | |
27 | const MergeTreeIndexMinMax & index; |
28 | std::vector<Range> parallelogram; |
29 | }; |
30 | |
31 | |
32 | struct MergeTreeIndexAggregatorMinMax : IMergeTreeIndexAggregator |
33 | { |
34 | explicit MergeTreeIndexAggregatorMinMax(const MergeTreeIndexMinMax & index); |
35 | ~MergeTreeIndexAggregatorMinMax() override = default; |
36 | |
37 | bool empty() const override { return parallelogram.empty(); } |
38 | MergeTreeIndexGranulePtr getGranuleAndReset() override; |
39 | void update(const Block & block, size_t * pos, size_t limit) override; |
40 | |
41 | const MergeTreeIndexMinMax & index; |
42 | std::vector<Range> parallelogram; |
43 | }; |
44 | |
45 | |
46 | class MergeTreeIndexConditionMinMax : public IMergeTreeIndexCondition |
47 | { |
48 | public: |
49 | MergeTreeIndexConditionMinMax( |
50 | const SelectQueryInfo & query, |
51 | const Context & context, |
52 | const MergeTreeIndexMinMax & index); |
53 | |
54 | bool alwaysUnknownOrTrue() const override; |
55 | |
56 | bool mayBeTrueOnGranule(MergeTreeIndexGranulePtr idx_granule) const override; |
57 | |
58 | ~MergeTreeIndexConditionMinMax() override = default; |
59 | private: |
60 | const MergeTreeIndexMinMax & index; |
61 | KeyCondition condition; |
62 | }; |
63 | |
64 | |
65 | class MergeTreeIndexMinMax : public IMergeTreeIndex |
66 | { |
67 | public: |
68 | MergeTreeIndexMinMax( |
69 | String name_, |
70 | ExpressionActionsPtr expr_, |
71 | const Names & columns_, |
72 | const DataTypes & data_types_, |
73 | const Block & , |
74 | size_t granularity_) |
75 | : IMergeTreeIndex(name_, expr_, columns_, data_types_, header_, granularity_) {} |
76 | |
77 | ~MergeTreeIndexMinMax() override = default; |
78 | |
79 | MergeTreeIndexGranulePtr createIndexGranule() const override; |
80 | MergeTreeIndexAggregatorPtr createIndexAggregator() const override; |
81 | |
82 | MergeTreeIndexConditionPtr createIndexCondition( |
83 | const SelectQueryInfo & query, const Context & context) const override; |
84 | |
85 | bool mayBenefitFromIndexForIn(const ASTPtr & node) const override; |
86 | }; |
87 | |
88 | } |
89 | |