/root/doris/be/src/olap/iterators.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <cstddef> |
21 | | #include <memory> |
22 | | |
23 | | #include "common/status.h" |
24 | | #include "io/io_common.h" |
25 | | #include "olap/block_column_predicate.h" |
26 | | #include "olap/column_predicate.h" |
27 | | #include "olap/olap_common.h" |
28 | | #include "olap/rowset/segment_v2/ann_index/ann_topn_runtime.h" |
29 | | #include "olap/rowset/segment_v2/row_ranges.h" |
30 | | #include "olap/tablet_schema.h" |
31 | | #include "runtime/runtime_state.h" |
32 | | #include "vec/core/block.h" |
33 | | #include "vec/exprs/score_runtime.h" |
34 | | #include "vec/exprs/vexpr.h" |
35 | | |
36 | | namespace doris { |
37 | | |
38 | | class RowCursor; |
39 | | class Schema; |
40 | | class ColumnPredicate; |
41 | | |
42 | | namespace vectorized { |
43 | | struct IteratorRowRef; |
44 | | }; |
45 | | |
46 | | namespace segment_v2 { |
47 | | struct SubstreamIterator; |
48 | | } |
49 | | class StorageReadOptions { |
50 | | public: |
51 | | struct KeyRange { |
52 | | KeyRange() |
53 | | : lower_key(nullptr), |
54 | | include_lower(false), |
55 | | upper_key(nullptr), |
56 | 0 | include_upper(false) {} |
57 | | |
58 | | KeyRange(const RowCursor* lower_key_, bool include_lower_, const RowCursor* upper_key_, |
59 | | bool include_upper_) |
60 | 0 | : lower_key(lower_key_), |
61 | 0 | include_lower(include_lower_), |
62 | 0 | upper_key(upper_key_), |
63 | 0 | include_upper(include_upper_) {} |
64 | | |
65 | | // the lower bound of the range, nullptr if not existed |
66 | | const RowCursor* lower_key = nullptr; |
67 | | // whether `lower_key` is included in the range |
68 | | bool include_lower; |
69 | | // the upper bound of the range, nullptr if not existed |
70 | | const RowCursor* upper_key = nullptr; |
71 | | // whether `upper_key` is included in the range |
72 | | bool include_upper; |
73 | | }; |
74 | | |
75 | | // reader's key ranges, empty if not existed. |
76 | | // used by short key index to filter row blocks |
77 | | std::vector<KeyRange> key_ranges; |
78 | | |
79 | | // For unique-key merge-on-write, the effect is similar to delete_conditions |
80 | | // that filters out rows that are deleted in realtime. |
81 | | // For a particular row, if delete_bitmap.contains(rowid) means that row is |
82 | | // marked deleted and invisible to user anymore. |
83 | | // segment_id -> roaring::Roaring* |
84 | | std::unordered_map<uint32_t, std::shared_ptr<roaring::Roaring>> delete_bitmap; |
85 | | |
86 | | std::shared_ptr<AndBlockColumnPredicate> delete_condition_predicates = |
87 | | AndBlockColumnPredicate::create_shared(); |
88 | | // reader's column predicate, nullptr if not existed |
89 | | // used to fiter rows in row block |
90 | | std::vector<std::shared_ptr<ColumnPredicate>> column_predicates; |
91 | | std::unordered_map<int32_t, std::shared_ptr<AndBlockColumnPredicate>> col_id_to_predicates; |
92 | | std::unordered_map<int32_t, std::vector<std::shared_ptr<const ColumnPredicate>>> |
93 | | del_predicates_for_zone_map; |
94 | | TPushAggOp::type push_down_agg_type_opt = TPushAggOp::NONE; |
95 | | |
96 | | // REQUIRED (null is not allowed) |
97 | | OlapReaderStatistics* stats = nullptr; |
98 | | bool use_page_cache = false; |
99 | | uint32_t block_row_max = 4096 - 32; // see https://github.com/apache/doris/pull/11816 |
100 | | |
101 | | TabletSchemaSPtr tablet_schema = nullptr; |
102 | | bool enable_unique_key_merge_on_write = false; |
103 | | bool record_rowids = false; |
104 | | std::vector<int> topn_filter_source_node_ids; |
105 | | int topn_filter_target_node_id = -1; |
106 | | // used for special optimization for query : ORDER BY key DESC LIMIT n |
107 | | bool read_orderby_key_reverse = false; |
108 | | // columns for orderby keys |
109 | | std::vector<uint32_t>* read_orderby_key_columns = nullptr; |
110 | | io::IOContext io_ctx; |
111 | | vectorized::VExpr* remaining_vconjunct_root = nullptr; |
112 | | std::vector<vectorized::VExprSPtr> remaining_conjunct_roots; |
113 | | vectorized::VExprContextSPtrs common_expr_ctxs_push_down; |
114 | | const std::set<int32_t>* output_columns = nullptr; |
115 | | // runtime state |
116 | | RuntimeState* runtime_state = nullptr; |
117 | | RowsetId rowset_id; |
118 | | Version version; |
119 | | int64_t tablet_id = 0; |
120 | | // slots that cast may be eliminated in storage layer |
121 | | std::map<std::string, vectorized::DataTypePtr> target_cast_type_for_variants; |
122 | | RowRanges row_ranges; |
123 | | size_t topn_limit = 0; |
124 | | |
125 | | std::map<ColumnId, vectorized::VExprContextSPtr> virtual_column_exprs; |
126 | | std::shared_ptr<segment_v2::AnnTopNRuntime> ann_topn_runtime; |
127 | | std::map<ColumnId, size_t> vir_cid_to_idx_in_block; |
128 | | std::map<size_t, vectorized::DataTypePtr> vir_col_idx_to_type; |
129 | | |
130 | | std::map<int32_t, TColumnAccessPaths> all_access_paths; |
131 | | std::map<int32_t, TColumnAccessPaths> predicate_access_paths; |
132 | | |
133 | | std::shared_ptr<vectorized::ScoreRuntime> score_runtime; |
134 | | CollectionStatisticsPtr collection_statistics; |
135 | | }; |
136 | | |
137 | | struct CompactionSampleInfo { |
138 | | int64_t bytes = 0; |
139 | | int64_t rows = 0; |
140 | | int64_t group_data_size = 0; |
141 | | }; |
142 | | |
143 | | struct BlockWithSameBit { |
144 | | vectorized::Block* block; |
145 | | std::vector<bool>& same_bit; |
146 | | |
147 | 201 | bool empty() const { return block->rows() == 0; } |
148 | | }; |
149 | | |
150 | | class RowwiseIterator; |
151 | | using RowwiseIteratorUPtr = std::unique_ptr<RowwiseIterator>; |
152 | | class RowwiseIterator { |
153 | | public: |
154 | 11.7k | RowwiseIterator() = default; |
155 | 11.7k | virtual ~RowwiseIterator() = default; |
156 | | |
157 | | // Initialize this iterator and make it ready to read with |
158 | | // input options. |
159 | | // Input options may contain scan range in which this scan. |
160 | | // Return Status::OK() if init successfully, |
161 | | // Return other error otherwise |
162 | 0 | virtual Status init(const StorageReadOptions& opts) { |
163 | 0 | return Status::InternalError("to be implemented, current class: " + |
164 | 0 | demangle(typeid(*this).name())); |
165 | 0 | } |
166 | | |
167 | 0 | virtual Status init(const StorageReadOptions& opts, CompactionSampleInfo* sample_info) { |
168 | 0 | return Status::InternalError("should not reach here, current class: " + |
169 | 0 | demangle(typeid(*this).name())); |
170 | 0 | } |
171 | | |
172 | | // If there is any valid data, this function will load data |
173 | | // into input batch with Status::OK() returned |
174 | | // If there is no data to read, will return Status::EndOfFile. |
175 | | // If other error happens, other error code will be returned. |
176 | 0 | virtual Status next_batch(vectorized::Block* block) { |
177 | 0 | return Status::InternalError("should not reach here, current class: " + |
178 | 0 | demangle(typeid(*this).name())); |
179 | 0 | } |
180 | | |
181 | 0 | virtual Status next_batch(BlockWithSameBit* block_with_same_bit) { |
182 | 0 | return Status::InternalError("should not reach here, current class: " + |
183 | 0 | demangle(typeid(*this).name())); |
184 | 0 | } |
185 | | |
186 | 0 | virtual Status next_batch(vectorized::BlockView* block_view) { |
187 | 0 | return Status::InternalError("should not reach here, current class: " + |
188 | 0 | demangle(typeid(*this).name())); |
189 | 0 | } |
190 | | |
191 | 0 | virtual Status next_row(vectorized::IteratorRowRef* ref) { |
192 | 0 | return Status::InternalError("should not reach here, current class: " + |
193 | 0 | demangle(typeid(*this).name())); |
194 | 0 | } |
195 | 0 | virtual Status unique_key_next_row(vectorized::IteratorRowRef* ref) { |
196 | 0 | return Status::InternalError("should not reach here, current class: " + |
197 | 0 | demangle(typeid(*this).name())); |
198 | 0 | } |
199 | | |
200 | 0 | virtual bool is_merge_iterator() const { return false; } |
201 | | |
202 | 0 | virtual Status current_block_row_locations(std::vector<RowLocation>* block_row_locations) { |
203 | 0 | return Status::InternalError("should not reach here, current class: " + |
204 | 0 | demangle(typeid(*this).name())); |
205 | 0 | } |
206 | | |
207 | | // return schema for this Iterator |
208 | | virtual const Schema& schema() const = 0; |
209 | | |
210 | | // Return the data id such as segment id, used for keep the insert order when do |
211 | | // merge sort in priority queue |
212 | 26.2k | virtual uint64_t data_id() const { return 0; } |
213 | | |
214 | 0 | virtual void update_profile(RuntimeProfile* profile) {} |
215 | | // return rows merged count by iterator |
216 | 0 | virtual uint64_t merged_rows() const { return 0; } |
217 | | |
218 | | // return if it's an empty iterator |
219 | 5.58k | virtual bool empty() const { return false; } |
220 | | }; |
221 | | |
222 | | } // namespace doris |