be/src/storage/segment/segment_iterator.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 <gen_cpp/Exprs_types.h> |
21 | | |
22 | | #include <cstddef> |
23 | | #include <cstdint> |
24 | | #include <map> |
25 | | #include <memory> |
26 | | #include <roaring/roaring.hh> |
27 | | #include <set> |
28 | | #include <string> |
29 | | #include <unordered_map> |
30 | | #include <utility> |
31 | | #include <vector> |
32 | | |
33 | | #include "common/status.h" |
34 | | #include "core/block/adaptive_block_size_predictor.h" |
35 | | #include "core/block/block.h" |
36 | | #include "core/block/column_with_type_and_name.h" |
37 | | #include "core/block/columns_with_type_and_name.h" |
38 | | #include "core/column/column.h" |
39 | | #include "core/data_type/data_type.h" |
40 | | #include "core/data_type/primitive_type.h" |
41 | | #include "core/field.h" |
42 | | #include "exec/common/variant_util.h" |
43 | | #include "exprs/score_runtime.h" |
44 | | #include "exprs/vexpr_fwd.h" |
45 | | #include "io/fs/file_reader_writer_fwd.h" |
46 | | #include "runtime/runtime_profile.h" |
47 | | #include "storage/index/ann/ann_topn_runtime.h" |
48 | | #include "storage/index/index_iterator.h" |
49 | | #include "storage/iterators.h" |
50 | | #include "storage/olap_common.h" |
51 | | #include "storage/predicate/block_column_predicate.h" |
52 | | #include "storage/predicate/column_predicate.h" |
53 | | #include "storage/row_cursor.h" |
54 | | #include "storage/schema.h" |
55 | | #include "storage/segment/common.h" |
56 | | #include "storage/segment/segment.h" |
57 | | #include "util/json/path_in_data.h" |
58 | | #include "util/slice.h" |
59 | | |
60 | | namespace doris { |
61 | | |
62 | | class VExpr; |
63 | | class VExprContext; |
64 | | struct RowLocation; |
65 | | |
66 | | namespace segment_v2 { |
67 | | |
68 | | class ColumnIterator; |
69 | | class RowRanges; |
70 | | class IndexIterator; |
71 | | |
72 | | class SegmentIterator : public RowwiseIterator { |
73 | | public: |
74 | | // Within SegmentIterator, ColumnId means an ordinal in the read schema. |
75 | | // Storage UIDs and caller-visible Block positions are named explicitly. |
76 | | SegmentIterator(std::shared_ptr<Segment> segment, ReadSchemaSPtr schema); |
77 | | ~SegmentIterator() override; |
78 | | |
79 | | [[nodiscard]] Status init_iterators(); |
80 | | [[nodiscard]] Status init(const StorageReadOptions& opts) override; |
81 | | [[nodiscard]] Status next_batch(Block* block) override; |
82 | | |
83 | | // Get current block row locations. This function should be called |
84 | | // after the `next_batch` function. |
85 | | // Only vectorized version is supported. |
86 | | [[nodiscard]] Status current_block_row_locations( |
87 | | std::vector<RowLocation>* block_row_locations) override; |
88 | | |
89 | 268 | const ReadSchema& schema() const override { return *_schema; } |
90 | 15 | uint64_t data_id() const override { return _segment->id(); } |
91 | | |
92 | 0 | void update_profile(RuntimeProfile* profile) override { |
93 | 0 | _update_profile(profile, _short_cir_eval_predicate, "ShortCircuitPredicates"); |
94 | 0 | _update_profile(profile, _pre_eval_block_predicate, "PreEvaluatePredicates"); |
95 | |
|
96 | 0 | if (_opts.delete_condition_predicates != nullptr) { |
97 | 0 | std::set<std::shared_ptr<const ColumnPredicate>> delete_predicate_set; |
98 | 0 | _opts.delete_condition_predicates->get_all_column_predicate(delete_predicate_set); |
99 | 0 | _update_profile(profile, delete_predicate_set, "DeleteConditionPredicates"); |
100 | 0 | } |
101 | 0 | } |
102 | | |
103 | 204 | bool has_index_in_iterators() const { |
104 | 204 | return std::any_of(_index_iterators.begin(), _index_iterators.end(), |
105 | 418 | [](const auto& iterator) { return iterator != nullptr; }); |
106 | 204 | } |
107 | | |
108 | | private: |
109 | | Status _next_batch_internal(Block* block); |
110 | | |
111 | | Status _check_output_block(Block* block); |
112 | | |
113 | | template <typename Container> |
114 | | void _update_profile(RuntimeProfile* profile, const Container& predicates, |
115 | 0 | const std::string& title) { |
116 | 0 | if (predicates.empty()) { |
117 | 0 | return; |
118 | 0 | } |
119 | 0 | std::string info; |
120 | 0 | for (auto pred : predicates) { |
121 | 0 | info += "\n" + pred->debug_string(); |
122 | 0 | } |
123 | 0 | profile->add_info_string(title, info); |
124 | 0 | } Unexecuted instantiation: _ZN5doris10segment_v215SegmentIterator15_update_profileISt6vectorISt10shared_ptrINS_15ColumnPredicateEESaIS6_EEEEvPNS_14RuntimeProfileERKT_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Unexecuted instantiation: _ZN5doris10segment_v215SegmentIterator15_update_profileISt3setISt10shared_ptrIKNS_15ColumnPredicateEESt4lessIS7_ESaIS7_EEEEvPNS_14RuntimeProfileERKT_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE |
125 | | |
126 | | [[nodiscard]] Status _lazy_init(Block* block); |
127 | | [[nodiscard]] Status _init_impl(const StorageReadOptions& opts); |
128 | | [[nodiscard]] Status _init_column_iterators(); |
129 | | [[nodiscard]] Status _init_index_iterators(); |
130 | | |
131 | | // calculate row ranges that fall into requested key ranges using short key index |
132 | | [[nodiscard]] Status _get_row_ranges_by_keys(); |
133 | | [[nodiscard]] Status _prepare_seek(const StorageReadOptions::KeyRange& key_range); |
134 | | [[nodiscard]] Status _lookup_ordinal(const RowCursor& key, bool is_include, rowid_t upper_bound, |
135 | | rowid_t* rowid); |
136 | | // lookup the ordinal of given key from short key index |
137 | | // the returned rowid is rowid in primary index, not the rowid encoded in primary key |
138 | | [[nodiscard]] Status _lookup_ordinal_from_sk_index(const RowCursor& key, bool is_include, |
139 | | rowid_t upper_bound, rowid_t* rowid); |
140 | | // lookup the ordinal of given key from primary key index |
141 | | [[nodiscard]] Status _lookup_ordinal_from_pk_index(const RowCursor& key, bool is_include, |
142 | | rowid_t* rowid); |
143 | | [[nodiscard]] Status _seek_and_peek(rowid_t rowid); |
144 | | |
145 | | // calculate row ranges that satisfy requested column conditions using various column index |
146 | | [[nodiscard]] Status _get_row_ranges_by_column_conditions(); |
147 | | [[nodiscard]] Status _get_row_ranges_from_conditions(RowRanges* condition_row_ranges); |
148 | | [[nodiscard]] Status _apply_expr_zonemap_to_row_ranges(const VExprContextSPtrs& conjuncts, |
149 | | rowid_t min_rowid, |
150 | | RowRanges* row_ranges); |
151 | | [[nodiscard]] Status _apply_inverted_index(); |
152 | | [[nodiscard]] Status _apply_inverted_index_on_column_predicate( |
153 | | std::shared_ptr<ColumnPredicate> pred, |
154 | | std::vector<std::shared_ptr<ColumnPredicate>>& remaining_predicates, |
155 | | bool* continue_apply); |
156 | | [[nodiscard]] Status _apply_ann_topn_predicate(); |
157 | | [[nodiscard]] Status _apply_index_expr(); |
158 | | // G02: true iff answering the single pushed-down MATCH predicate by its |
159 | | // match COUNT alone is indistinguishable from the row-accurate bitmap for |
160 | | // this COUNT_ON_INDEX scan (no deletes, no other filters, full row bitmap, |
161 | | // no row-id consumers). Gates IndexQueryContext::count_on_index_fastpath; |
162 | | // the decision predicate itself lives in count_on_index_fastpath.h. |
163 | | bool _count_on_index_fastpath_safe() const; |
164 | | // G03: teardown of the G02 handshake. Captures whether the reader answered |
165 | | // with a fabricated count bitmap into _count_fastpath_hit and clears both |
166 | | // context flags so no later read_from_index call can observe or forge |
167 | | // them. Runs on every exit of the index-apply scope. |
168 | | void _capture_count_fastpath_hit(); |
169 | | // G03: true iff the per-batch defaults fill of _read_columns_by_index |
170 | | // would apply to `cid` (the _no_need_read_key_data or _prune_column |
171 | | // branch) AND the block column needs no storage->schema cast, i.e. the |
172 | | // emission shortcut can reproduce the column's batch content exactly. |
173 | | bool _column_emits_defaults_for_count(ColumnId cid); |
174 | | // G03: fills CountEmitShortcutFacts from live iterator state at the end of |
175 | | // _lazy_init and returns the pure-guard verdict; the decision predicate |
176 | | // itself lives in count_on_index_fastpath.h. |
177 | | bool _should_engage_count_emit_shortcut(const Block* block); |
178 | | // G03: one emission-shortcut batch: min(remaining, kCountEmitBatchRows) |
179 | | // default rows filled straight into the block (NOT-NULL defaults for |
180 | | // nullable columns, mirroring _prune_column), then EOF once the countdown |
181 | | // reaches zero. Replaces the whole per-rowid _next_batch_internal body for |
182 | | // engaged scans. |
183 | | Status _emit_count_shortcut_batch(Block* block); |
184 | | |
185 | | bool _column_has_fulltext_index(int32_t cid); |
186 | | bool _column_has_ann_index(int32_t cid); |
187 | | bool _downgrade_without_index(Status res, bool need_remaining = false); |
188 | | inline bool _inverted_index_not_support_pred_type(const PredicateType& type); |
189 | | |
190 | | void _init_column_states(); |
191 | | void _rebuild_scan_predicate_states(); |
192 | | void _mark_common_expr_states(const VExprSPtr& expr); |
193 | | Status _vec_init_lazy_materialization(); |
194 | | |
195 | 11.9k | uint32_t segment_id() const { return _segment->id(); } |
196 | 14.7k | uint32_t num_rows() const { return _segment->num_rows(); } |
197 | | |
198 | | [[nodiscard]] Status _read_columns_by_index(const std::vector<ColumnId>& read_ordinals, |
199 | | uint32_t nrows_read_limit, uint16_t& nrows_read); |
200 | | void _replace_version_col_if_needed(const std::vector<ColumnId>& ordinals, size_t num_rows); |
201 | | void _update_tso_col_if_needed(const std::vector<ColumnId>& ordinals, size_t num_rows); |
202 | | Status _init_current_block(Block* block, std::vector<MutableColumnPtr>& non_pred_vector, |
203 | | uint32_t nrows_read_limit); |
204 | | uint16_t _evaluate_vectorization_predicate(uint16_t* sel_rowid_idx, uint16_t selected_size); |
205 | | uint16_t _evaluate_short_circuit_predicate(uint16_t* sel_rowid_idx, uint16_t selected_size); |
206 | | Status _apply_read_limit_to_selected_rows(Block* block, uint16_t& selected_size); |
207 | | Status _output_columns_to_block(Block* block); |
208 | | [[nodiscard]] Status _read_columns_by_rowids(const std::vector<ColumnId>& read_ordinals, |
209 | | std::vector<rowid_t>& rowid_vector, |
210 | | uint16_t* sel_rowid_idx, size_t select_size, |
211 | | MutableColumns* mutable_columns, |
212 | | bool init_condition_cache = false, |
213 | | bool read_for_predicate = false); |
214 | | [[nodiscard]] Status _read_lazy_pruned_columns(Block* block); |
215 | | |
216 | | Status copy_column_data_by_selector(IColumn* input_col_ptr, MutableColumnPtr& output_col, |
217 | | uint16_t* sel_rowid_idx, uint16_t select_size, |
218 | | size_t batch_size); |
219 | | |
220 | | template <class Container> |
221 | | [[nodiscard]] Status _output_column_by_sel_idx(Block* block, const Container& ordinals, |
222 | 1.68k | uint16_t* sel_rowid_idx, uint16_t select_size) { |
223 | 1.68k | SCOPED_RAW_TIMER(&_opts.stats->output_col_ns); |
224 | 1.68k | for (auto ordinal : ordinals) { |
225 | 1.68k | if (ordinal >= _schema->num_block_columns()) { |
226 | 510 | continue; |
227 | 510 | } |
228 | 1.17k | const auto& file_column_type = _storage_name_and_type[ordinal].second; |
229 | 1.17k | if (!file_column_type->equals(*block->get_by_position(ordinal).type)) { |
230 | | // Do additional cast |
231 | 0 | MutableColumnPtr tmp = file_column_type->create_column(); |
232 | 0 | RETURN_IF_ERROR(copy_column_data_by_selector(_current_columns[ordinal].get(), tmp, |
233 | 0 | sel_rowid_idx, select_size, |
234 | 0 | _opts.block_row_max)); |
235 | 0 | RETURN_IF_ERROR(variant_util::cast_column({tmp->get_ptr(), file_column_type, ""}, |
236 | 0 | block->get_by_position(ordinal).type, |
237 | 0 | &block->get_by_position(ordinal).column)); |
238 | 1.17k | } else { |
239 | 1.17k | MutableColumnPtr output_column = |
240 | 1.17k | block->get_by_position(ordinal).column->assert_mutable(); |
241 | 1.17k | RETURN_IF_ERROR(copy_column_data_by_selector(_current_columns[ordinal].get(), |
242 | 1.17k | output_column, sel_rowid_idx, |
243 | 1.17k | select_size, _opts.block_row_max)); |
244 | 1.17k | } |
245 | 1.17k | } |
246 | 1.68k | return Status::OK(); |
247 | 1.68k | } |
248 | | |
249 | | bool _can_evaluated_by_vectorized(std::shared_ptr<ColumnPredicate> predicate); |
250 | | |
251 | | [[nodiscard]] Status _execute_common_expr(uint16_t* sel_rowid_idx, uint16_t& selected_size, |
252 | | Block* block); |
253 | | Status _process_common_expr(uint16_t* sel_rowid_idx, uint16_t& selected_size, Block* block); |
254 | | |
255 | | uint16_t _evaluate_common_expr_filter(uint16_t* sel_rowid_idx, uint16_t selected_size, |
256 | | const IColumn::Filter& filter); |
257 | | |
258 | | // Dictionary column should do something to initial. |
259 | | void _convert_dict_code_for_predicate_if_necessary(); |
260 | | |
261 | | void _convert_dict_code_for_predicate_if_necessary_impl(const ColumnPredicate& predicate); |
262 | | |
263 | | bool _check_apply_by_inverted_index(std::shared_ptr<ColumnPredicate> pred); |
264 | | |
265 | | void _output_index_result_column(const VExprContextSPtrs& expr_ctxs, uint16_t* sel_rowid_idx, |
266 | | uint16_t select_size); |
267 | | |
268 | | bool _need_read_data(ColumnId cid); |
269 | | bool _prune_column(ColumnId cid, MutableColumnPtr& column, size_t num_of_defaults); |
270 | | |
271 | | Status _construct_compound_expr_context(); |
272 | | |
273 | | // Both the key cursor and _seek_block lay out the leading tablet key |
274 | | // columns densely, so position i addresses the same column in both. |
275 | 0 | int _compare_short_key_with_seek_block(const RowCursor& key, size_t num_key_cols) { |
276 | 0 | for (uint32_t i = 0; i < num_key_cols; ++i) { |
277 | 0 | auto ord = key.field(i) <=> (*_seek_block[i])[0]; |
278 | 0 | if (ord != std::strong_ordering::equal) { |
279 | 0 | return ord == std::strong_ordering::less ? -1 : 1; |
280 | 0 | } |
281 | 0 | } |
282 | 0 | return 0; |
283 | 0 | } |
284 | | |
285 | | Status _convert_column_to_expected_type(ColumnId column_id); |
286 | | Status _convert_to_expected_type(const std::vector<ColumnId>& ordinals); |
287 | | |
288 | | bool _no_need_read_key_data(ColumnId cid, MutableColumnPtr& column, size_t nrows_read); |
289 | | // Side-effect-free eligibility half of _no_need_read_key_data (no column |
290 | | // fill); shared by the per-batch fill and the G03 engage-time per-column |
291 | | // proof so the two can never drift. |
292 | | bool _no_need_read_key_data_eligible(ColumnId cid); |
293 | | |
294 | | bool _has_delete_pred(ColumnId cid) const; |
295 | | bool _has_lazy_pruned_children(ColumnId cid) const; |
296 | | bool _can_skip_reading_extra_column(ColumnId cid); |
297 | | |
298 | | bool _can_opt_limit_reads(); |
299 | | |
300 | | void _initialize_predicate_results(); |
301 | | bool _check_all_conditions_passed_inverted_index_for_column(ColumnId cid, |
302 | | bool default_return = false); |
303 | | |
304 | | void _calculate_common_expr_index_exec_status(); |
305 | | |
306 | | Status _process_eof(Block* block); |
307 | | |
308 | | void _fill_column_nothing(); |
309 | | |
310 | | Status _process_columns(const std::vector<ColumnId>& ordinals, Block* block); |
311 | | |
312 | | // Initialize virtual columns in the block, set all virtual columns in the block to ColumnNothing |
313 | | void _init_virtual_columns(Block* block); |
314 | | // Fallback logic for virtual column materialization, materializing all unmaterialized virtual columns through expressions |
315 | | Status _materialization_of_virtual_column(Block* block); |
316 | | void _prepare_score_column_materialization(); |
317 | | |
318 | | void _init_row_bitmap_by_condition_cache(); |
319 | | |
320 | | void _init_segment_prefetchers(); |
321 | | |
322 | | class BitmapRangeIterator; |
323 | | class BackwardBitmapRangeIterator; |
324 | | |
325 | | // Example: |
326 | | // SELECT k, s.b, o FROM t |
327 | | // WHERE k > 1 AND abs(k) < 10 AND abs(s.a) < 5; |
328 | | // ReadSchema ordinals: [0:k, 1:s STRUCT<a,b>, 2:o] |
329 | | // When no filter is fully evaluated by an index: |
330 | | // state[0:k] = {has_delete_pred=false, has_scan_pred=true, |
331 | | // has_common_expr=true, need_read_data=true} |
332 | | // state[1:s] = {has_delete_pred=false, has_scan_pred=false, |
333 | | // has_common_expr=true, need_read_data=true} |
334 | | // state[2:o] = {has_delete_pred=false, has_scan_pred=false, |
335 | | // has_common_expr=false, need_read_data=true} |
336 | | // A storage-only column appended for a delete condition would have |
337 | | // has_delete_pred=true. |
338 | | struct ColumnReadState { |
339 | | bool has_delete_pred = false; |
340 | | // Mirrors the mutable _col_predicates list: initially all safe scan |
341 | | // predicates, then only residual predicates after index evaluation. |
342 | | bool has_scan_pred = false; |
343 | | bool has_common_expr = false; |
344 | | // Index evaluation sets this to false when it fully supplies the column result. |
345 | | // _need_read_data() applies the remaining read constraints. |
346 | | bool need_read_data = true; |
347 | | |
348 | 116k | bool has_predicate() const { return has_delete_pred || has_scan_pred; } |
349 | | }; |
350 | | |
351 | | std::shared_ptr<Segment> _segment; |
352 | | // read schema from scanner |
353 | | ReadSchemaSPtr _schema; |
354 | | // Inverted-index field name and storage/materialization type for each ReadSchema column. |
355 | | std::vector<IndexFieldNameAndTypePair> _storage_name_and_type; |
356 | | // vector idx -> column iterarator |
357 | | std::vector<std::unique_ptr<ColumnIterator>> _column_iterators; |
358 | | std::vector<std::unique_ptr<IndexIterator>> _index_iterators; |
359 | | // after init(), `_row_bitmap` contains all rowid to scan |
360 | | roaring::Roaring _row_bitmap; |
361 | | // an iterator for `_row_bitmap` that can be used to extract row range to scan |
362 | | std::unique_ptr<BitmapRangeIterator> _range_iter; |
363 | | // the next rowid to read |
364 | | rowid_t _cur_rowid; |
365 | | // members related to lazy materialization read |
366 | | // -------------------------------------------- |
367 | | // remember the rowids we've read for the current row block. |
368 | | // could be a local variable of next_batch(), kept here to reuse vector memory |
369 | | std::vector<rowid_t> _block_rowids; |
370 | | bool _is_need_vec_eval = false; |
371 | | bool _is_need_short_eval = false; |
372 | | bool _is_need_expr_eval = false; |
373 | | |
374 | | bool _enable_prune_nested_column = false; |
375 | | |
376 | | // Per-column state indexed by read schema ordinal. Ordered column lists |
377 | | // below are execution plans rather than additional column membership sets. |
378 | | std::vector<ColumnReadState> _column_states; |
379 | | // Columns of the current batch, indexed by read schema ordinal. |
380 | | MutableColumns _current_columns; |
381 | | std::vector<std::shared_ptr<ColumnPredicate>> _pre_eval_block_predicate; |
382 | | std::vector<std::shared_ptr<ColumnPredicate>> _short_cir_eval_predicate; |
383 | | // Example: |
384 | | // SELECT k, s.b, o FROM t |
385 | | // WHERE k > 1 AND abs(k) < 10 AND abs(s.a) < 5; |
386 | | // ReadSchema ordinals: [0:k, 1:s STRUCT<a,b>, 2:o] |
387 | | // |
388 | | // The first three lists assign each active column to its earliest materialization stage: |
389 | | // _predicate_ordinals = [0] // k is used by both k > 1 and abs(k) < 10; predicate wins. |
390 | | // _common_expr_ordinals = [1] // s is read for the abs(s.a) < 5 expression. |
391 | | // _output_ordinals = [2] // o is needed only by output. |
392 | | std::vector<ColumnId> _predicate_ordinals; |
393 | | std::vector<ColumnId> _common_expr_ordinals; |
394 | | std::vector<ColumnId> _output_ordinals; |
395 | | // _lazy_pruned_ordinals = [1] // After filtering on s.a, read s.b for surviving rows. |
396 | | // Unlike the first three disjoint lists, this recovery list may contain the same ordinal. |
397 | | std::vector<ColumnId> _lazy_pruned_ordinals; |
398 | | |
399 | | // the actual init process is delayed to the first call to next_batch() |
400 | | bool _lazy_inited; |
401 | | bool _inited; |
402 | | |
403 | | StorageReadOptions _opts; |
404 | | // Adaptive batch size predictor; null when the feature is disabled. |
405 | | std::unique_ptr<AdaptiveBlockSizePredictor> _block_size_predictor; |
406 | | // Build the AdaptiveBlockSizePredictor for this segment based on segment footer |
407 | | // metadata for the projected output columns. Returns nullptr if the feature is |
408 | | // disabled or the byte budget is non-positive. |
409 | | std::unique_ptr<AdaptiveBlockSizePredictor> _make_block_size_predictor() const; |
410 | | // Snapshot of _opts.block_row_max at init time; used as the hard upper bound so that |
411 | | // dynamic adjustments never exceed the capacity of pre-allocated buffers. |
412 | | uint32_t _initial_block_row_max = 0; |
413 | | // make a copy of `_opts.column_predicates` in order to make local changes |
414 | | std::vector<std::shared_ptr<ColumnPredicate>> _col_predicates; |
415 | | VExprContextSPtrs _common_expr_ctxs_push_down; |
416 | | // row schema of the key to seek |
417 | | // only used in `_get_row_ranges_by_keys` |
418 | | std::unique_ptr<ReadSchema> _seek_schema; |
419 | | // used to binary search the rowid for a given key |
420 | | // only used in `_get_row_ranges_by_keys` |
421 | | MutableColumns _seek_block; |
422 | | // Per-seek-schema-ordinal column iterators for the short-key seek path. |
423 | | // Points into _column_iterators when the key column is also read, otherwise |
424 | | // into _owned_seek_column_iterators (a seek key column may not be part of |
425 | | // the read schema at all). |
426 | | std::vector<ColumnIterator*> _seek_column_iterators; |
427 | | std::vector<std::unique_ptr<ColumnIterator>> _owned_seek_column_iterators; |
428 | | |
429 | | io::FileReaderSPtr _file_reader; |
430 | | |
431 | | // used for compaction, record selectd rowids of current batch |
432 | | uint16_t _selected_size; |
433 | | std::vector<uint16_t> _sel_rowid_idx; |
434 | | |
435 | | // Rows already produced by this iterator. Used together with |
436 | | // _opts.read_limit to compute the remaining per-batch budget. |
437 | | size_t _rows_returned = 0; |
438 | | |
439 | | int64_t _tablet_id = 0; |
440 | | // Column UIDs requested by the caller. A -1 entry means light schema change is disabled and |
441 | | // the column has no UID, so the _need_read_data() optimization is disabled. |
442 | | std::set<int32_t> _output_column_uids; |
443 | | |
444 | | std::vector<uint8_t> _ret_flags; |
445 | | |
446 | | /* |
447 | | * column and column_predicates on it. |
448 | | * a boolean value to indicate whether the column has been read by the index. |
449 | | */ |
450 | | std::unordered_map<ColumnId, std::unordered_map<std::shared_ptr<ColumnPredicate>, bool>> |
451 | | _column_predicate_index_exec_status; |
452 | | |
453 | | /* |
454 | | * column and common expr on it. |
455 | | * a boolean value to indicate whether the column has been read by the index. |
456 | | */ |
457 | | std::unordered_map<ColumnId, std::unordered_map<const VExpr*, bool>> |
458 | | _common_expr_index_exec_status; |
459 | | |
460 | | /* |
461 | | * common expr context to slotref map |
462 | | * slot ref map is used to get slot ref expr by using column id. |
463 | | */ |
464 | | std::unordered_map<VExprContext*, std::unordered_map<ColumnId, VExpr*>> |
465 | | _common_expr_to_slotref_map; |
466 | | |
467 | | ScoreRuntimeSPtr _score_runtime; |
468 | | |
469 | | std::shared_ptr<segment_v2::AnnTopNRuntime> _ann_topn_runtime; |
470 | | |
471 | | // cid to virtual column expr |
472 | | std::map<ColumnId, VExprContextSPtr> _virtual_column_exprs; |
473 | | |
474 | | IndexQueryContextPtr _index_query_context; |
475 | | |
476 | | // G03 count-emission shortcut state (see count_on_index_fastpath.h). |
477 | | // _count_fastpath_hit: the reader answered the single MATCH predicate with |
478 | | // a fabricated count bitmap (captured from the G02 handshake reply). |
479 | | // _count_emit_shortcut: engaged at the end of _lazy_init when |
480 | | // count_emit_shortcut_safe holds; every subsequent batch is emitted by |
481 | | // _emit_count_shortcut_batch from _count_emit_rows_remaining (initialized |
482 | | // to the post-apply _row_bitmap cardinality) without touching the row |
483 | | // bitmap iterator. |
484 | | bool _count_fastpath_hit = false; |
485 | | bool _count_emit_shortcut = false; |
486 | | uint64_t _count_emit_rows_remaining = 0; |
487 | | // Batch size for shortcut emission: VStatisticsIterator's |
488 | | // MAX_ROW_SIZE_IN_COUNT, the largest default-rows block shape already |
489 | | // proven through every consumer above the segment iterator by the plain |
490 | | // COUNT pushdown (rowset reader, collect iterator, block reader, scanner). |
491 | | static constexpr uint64_t kCountEmitBatchRows = 65535; |
492 | | |
493 | | // key is column uid, value is the sparse column cache |
494 | | std::unordered_map<int32_t, PathToBinaryColumnCacheUPtr> _variant_sparse_column_cache; |
495 | | |
496 | | bool _find_condition_cache = false; |
497 | | std::shared_ptr<std::vector<bool>> _condition_cache; |
498 | | static constexpr int CONDITION_CACHE_OFFSET = 2048; |
499 | | }; |
500 | | |
501 | | } // namespace segment_v2 |
502 | | } // namespace doris |