Coverage Report

Created: 2026-08-20 15:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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 <ostream>
27
#include <roaring/roaring.hh>
28
#include <set>
29
#include <string>
30
#include <unordered_map>
31
#include <utility>
32
#include <vector>
33
34
#include "common/status.h"
35
#include "core/block/adaptive_block_size_predictor.h"
36
#include "core/block/block.h"
37
#include "core/block/column_with_type_and_name.h"
38
#include "core/block/columns_with_type_and_name.h"
39
#include "core/column/column.h"
40
#include "core/data_type/data_type.h"
41
#include "core/data_type/primitive_type.h"
42
#include "core/field.h"
43
#include "exec/common/variant_util.h"
44
#include "exprs/score_runtime.h"
45
#include "exprs/vexpr_fwd.h"
46
#include "io/fs/file_reader_writer_fwd.h"
47
#include "runtime/runtime_profile.h"
48
#include "storage/index/ann/ann_topn_runtime.h"
49
#include "storage/index/index_iterator.h"
50
#include "storage/iterators.h"
51
#include "storage/olap_common.h"
52
#include "storage/predicate/block_column_predicate.h"
53
#include "storage/predicate/column_predicate.h"
54
#include "storage/row_cursor.h"
55
#include "storage/schema.h"
56
#include "storage/segment/common.h"
57
#include "storage/segment/segment.h"
58
#include "util/json/path_in_data.h"
59
#include "util/slice.h"
60
61
namespace doris {
62
63
class ObjectPool;
64
class MatchPredicate;
65
66
class VExpr;
67
class VExprContext;
68
struct RowLocation;
69
70
namespace segment_v2 {
71
72
class ColumnIterator;
73
class InvertedIndexIterator;
74
class RowRanges;
75
class IndexIterator;
76
77
struct ColumnPredicateInfo {
78
    ColumnPredicateInfo() = default;
79
80
0
    std::string debug_string() const {
81
0
        std::stringstream ss;
82
0
        ss << "column_name=" << column_name << ", query_op=" << query_op << ", query_value=";
83
0
        bool first = true;
84
0
        for (const auto& query_value : query_values) {
85
0
            if (!first) {
86
0
                ss << ",";
87
0
            }
88
0
            first = false;
89
0
            ss << query_value;
90
0
        }
91
0
        return ss.str();
92
0
    }
93
94
0
    bool is_empty() const {
95
0
        return column_name.empty() && query_values.empty() && query_op.empty();
96
0
    }
97
98
0
    bool is_equal(const ColumnPredicateInfo& column_pred_info) const {
99
0
        if (column_pred_info.column_name != column_name) {
100
0
            return false;
101
0
        }
102
0
103
0
        if (column_pred_info.query_values != query_values) {
104
0
            return false;
105
0
        }
106
0
107
0
        if (column_pred_info.query_op != query_op) {
108
0
            return false;
109
0
        }
110
0
111
0
        return true;
112
0
    }
113
114
    std::string column_name;
115
    // use set to ensure the consistent order of predicate_result_sign generated by inlist.
116
    std::set<std::string> query_values;
117
    std::string query_op;
118
    int32_t column_id;
119
};
120
121
class SegmentIterator : public RowwiseIterator {
122
public:
123
    SegmentIterator(std::shared_ptr<Segment> segment, SchemaSPtr schema);
124
    ~SegmentIterator() override;
125
126
    [[nodiscard]] Status init_iterators();
127
    [[nodiscard]] Status init(const StorageReadOptions& opts) override;
128
    [[nodiscard]] Status next_batch(Block* block) override;
129
130
    // Get current block row locations. This function should be called
131
    // after the `next_batch` function.
132
    // Only vectorized version is supported.
133
    [[nodiscard]] Status current_block_row_locations(
134
            std::vector<RowLocation>* block_row_locations) override;
135
136
268
    const Schema& schema() const override { return *_schema; }
137
0
    Segment& segment() { return *_segment; }
138
0
    StorageReadOptions& storage_read_options() { return _opts; }
139
15
    uint64_t data_id() const override { return _segment->id(); }
140
0
    RowsetId rowset_id() const { return _segment->rowset_id(); }
141
0
    int64_t tablet_id() const { return _tablet_id; }
142
143
0
    void update_profile(RuntimeProfile* profile) override {
144
0
        _update_profile(profile, _short_cir_eval_predicate, "ShortCircuitPredicates");
145
0
        _update_profile(profile, _pre_eval_block_predicate, "PreEvaluatePredicates");
146
147
0
        if (_opts.delete_condition_predicates != nullptr) {
148
0
            std::set<std::shared_ptr<const ColumnPredicate>> delete_predicate_set;
149
0
            _opts.delete_condition_predicates->get_all_column_predicate(delete_predicate_set);
150
0
            _update_profile(profile, delete_predicate_set, "DeleteConditionPredicates");
151
0
        }
152
0
    }
153
154
204
    bool has_index_in_iterators() const {
155
204
        return std::any_of(_index_iterators.begin(), _index_iterators.end(),
156
629
                           [](const auto& iterator) { return iterator != nullptr; });
157
204
    }
158
159
private:
160
    Status _next_batch_internal(Block* block);
161
162
    Status _check_output_block(Block* block);
163
164
    template <typename Container>
165
    void _update_profile(RuntimeProfile* profile, const Container& predicates,
166
0
                         const std::string& title) {
167
0
        if (predicates.empty()) {
168
0
            return;
169
0
        }
170
0
        std::string info;
171
0
        for (auto pred : predicates) {
172
0
            info += "\n" + pred->debug_string();
173
0
        }
174
0
        profile->add_info_string(title, info);
175
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
176
177
    [[nodiscard]] Status _lazy_init(Block* block);
178
    [[nodiscard]] Status _init_impl(const StorageReadOptions& opts);
179
    [[nodiscard]] Status _init_return_column_iterators();
180
    [[nodiscard]] Status _init_index_iterators();
181
182
    // calculate row ranges that fall into requested key ranges using short key index
183
    [[nodiscard]] Status _get_row_ranges_by_keys();
184
    [[nodiscard]] Status _prepare_seek(const StorageReadOptions::KeyRange& key_range);
185
    [[nodiscard]] Status _lookup_ordinal(const RowCursor& key, bool is_include, rowid_t upper_bound,
186
                                         rowid_t* rowid);
187
    // lookup the ordinal of given key from short key index
188
    // the returned rowid is rowid in primary index, not the rowid encoded in primary key
189
    [[nodiscard]] Status _lookup_ordinal_from_sk_index(const RowCursor& key, bool is_include,
190
                                                       rowid_t upper_bound, rowid_t* rowid);
191
    // lookup the ordinal of given key from primary key index
192
    [[nodiscard]] Status _lookup_ordinal_from_pk_index(const RowCursor& key, bool is_include,
193
                                                       rowid_t* rowid);
194
    [[nodiscard]] Status _seek_and_peek(rowid_t rowid);
195
196
    // calculate row ranges that satisfy requested column conditions using various column index
197
    [[nodiscard]] Status _get_row_ranges_by_column_conditions();
198
    [[nodiscard]] Status _get_row_ranges_from_conditions(RowRanges* condition_row_ranges);
199
    [[nodiscard]] Status _apply_expr_zonemap_to_row_ranges(const VExprContextSPtrs& conjuncts,
200
                                                           rowid_t min_rowid,
201
                                                           RowRanges* row_ranges);
202
    [[nodiscard]] Status _apply_inverted_index();
203
    [[nodiscard]] Status _apply_inverted_index_on_column_predicate(
204
            std::shared_ptr<ColumnPredicate> pred,
205
            std::vector<std::shared_ptr<ColumnPredicate>>& remaining_predicates,
206
            bool* continue_apply);
207
    [[nodiscard]] Status _apply_ann_topn_predicate();
208
    [[nodiscard]] Status _apply_index_expr();
209
    // G02: true iff answering the single pushed-down MATCH predicate by its
210
    // match COUNT alone is indistinguishable from the row-accurate bitmap for
211
    // this COUNT_ON_INDEX scan (no deletes, no other filters, full row bitmap,
212
    // no row-id consumers). Gates IndexQueryContext::count_on_index_fastpath;
213
    // the decision predicate itself lives in count_on_index_fastpath.h.
214
    bool _count_on_index_fastpath_safe() const;
215
    // G03: teardown of the G02 handshake. Captures whether the reader answered
216
    // with a fabricated count bitmap into _count_fastpath_hit and clears both
217
    // context flags so no later read_from_index call can observe or forge
218
    // them. Runs on every exit of the index-apply scope.
219
    void _capture_count_fastpath_hit();
220
    // G03: true iff the per-batch defaults fill of _read_columns_by_index
221
    // would apply to `cid` (the _no_need_read_key_data or _prune_column
222
    // branch) AND the block column needs no storage->schema cast, i.e. the
223
    // emission shortcut can reproduce the column's batch content exactly.
224
    bool _column_emits_defaults_for_count(ColumnId cid);
225
    // G03: fills CountEmitShortcutFacts from live iterator state at the end of
226
    // _lazy_init and returns the pure-guard verdict; the decision predicate
227
    // itself lives in count_on_index_fastpath.h.
228
    bool _should_engage_count_emit_shortcut(const Block* block);
229
    // G03: one emission-shortcut batch: min(remaining, kCountEmitBatchRows)
230
    // default rows filled straight into the block (NOT-NULL defaults for
231
    // nullable columns, mirroring _prune_column), then EOF once the countdown
232
    // reaches zero. Replaces the whole per-rowid _next_batch_internal body for
233
    // engaged scans.
234
    Status _emit_count_shortcut_batch(Block* block);
235
236
    bool _column_has_fulltext_index(int32_t cid);
237
    bool _column_has_ann_index(int32_t cid);
238
    bool _downgrade_without_index(Status res, bool need_remaining = false);
239
    inline bool _inverted_index_not_support_pred_type(const PredicateType& type);
240
    bool _is_literal_node(const TExprNodeType::type& node_type);
241
242
    Status _vec_init_lazy_materialization();
243
244
7.50k
    uint32_t segment_id() const { return _segment->id(); }
245
14.7k
    uint32_t num_rows() const { return _segment->num_rows(); }
246
247
    [[nodiscard]] Status _seek_columns(const std::vector<ColumnId>& column_ids, rowid_t pos);
248
    // read `nrows` of columns specified by `column_ids` into `block` at `row_offset`.
249
    // for vectorization implementation
250
    [[nodiscard]] Status _read_columns(const std::vector<ColumnId>& column_ids,
251
                                       MutableColumns& column_block, size_t nrows);
252
    [[nodiscard]] Status _read_columns_by_index(uint32_t nrows_read_limit, uint16_t& nrows_read);
253
    void _replace_version_col_if_needed(const std::vector<ColumnId>& column_ids, size_t num_rows);
254
    void _update_tso_col_if_needed(const std::vector<ColumnId>& column_ids, size_t num_rows);
255
    Status _init_current_block(Block* block, std::vector<MutableColumnPtr>& non_pred_vector,
256
                               uint32_t nrows_read_limit);
257
    uint16_t _evaluate_vectorization_predicate(uint16_t* sel_rowid_idx, uint16_t selected_size);
258
    uint16_t _evaluate_short_circuit_predicate(uint16_t* sel_rowid_idx, uint16_t selected_size);
259
    Status _apply_read_limit_to_selected_rows(Block* block, uint16_t& selected_size);
260
    void _collect_runtime_filter_predicate();
261
    Status _output_non_pred_columns(Block* block);
262
    [[nodiscard]] Status _read_columns_by_rowids(std::vector<ColumnId>& read_column_ids,
263
                                                 std::vector<rowid_t>& rowid_vector,
264
                                                 uint16_t* sel_rowid_idx, size_t select_size,
265
                                                 MutableColumns* mutable_columns,
266
                                                 bool init_condition_cache = false,
267
                                                 bool read_for_predicate = false);
268
    [[nodiscard]] Status _read_lazy_pruned_columns(Block* block);
269
270
    Status copy_column_data_by_selector(IColumn* input_col_ptr, MutableColumnPtr& output_col,
271
                                        uint16_t* sel_rowid_idx, uint16_t select_size,
272
                                        size_t batch_size);
273
274
    template <class Container>
275
    [[nodiscard]] Status _output_column_by_sel_idx(Block* block, const Container& column_ids,
276
1.68k
                                                   uint16_t* sel_rowid_idx, uint16_t select_size) {
277
1.68k
        SCOPED_RAW_TIMER(&_opts.stats->output_col_ns);
278
1.68k
        for (auto cid : column_ids) {
279
1.68k
            int block_cid = _schema->column_index(cid);
280
            // Only the additional deleted filter condition need to materialize column be at the end of the block
281
            // We should not to materialize the column of query engine do not need. So here just return OK.
282
            // Eg:
283
            //      `delete from table where a = 10;`
284
            //      `select b from table;`
285
            // a column only effective in segment iterator, the block from query engine only contain the b column.
286
            // so the `block_cid >= data.size()` is true
287
1.68k
            if (block_cid >= block->columns()) {
288
277
                continue;
289
277
            }
290
1.41k
            DataTypePtr storage_type = _segment->get_data_type_of(*_schema->column(cid), _opts);
291
1.41k
            if (storage_type && !storage_type->equals(*block->get_by_position(block_cid).type)) {
292
                // Do additional cast
293
0
                MutableColumnPtr tmp = storage_type->create_column();
294
0
                RETURN_IF_ERROR(copy_column_data_by_selector(_current_return_columns[cid].get(),
295
0
                                                             tmp, sel_rowid_idx, select_size,
296
0
                                                             _opts.block_row_max));
297
0
                RETURN_IF_ERROR(variant_util::cast_column(
298
0
                        {tmp->get_ptr(), storage_type, ""}, block->get_by_position(block_cid).type,
299
0
                        &block->get_by_position(block_cid).column));
300
1.41k
            } else {
301
1.41k
                MutableColumnPtr output_column =
302
1.41k
                        block->get_by_position(block_cid).column->assert_mutable();
303
1.41k
                RETURN_IF_ERROR(copy_column_data_by_selector(_current_return_columns[cid].get(),
304
1.41k
                                                             output_column, sel_rowid_idx,
305
1.41k
                                                             select_size, _opts.block_row_max));
306
1.41k
            }
307
1.41k
        }
308
1.68k
        return Status::OK();
309
1.68k
    }
310
311
    bool _can_evaluated_by_vectorized(std::shared_ptr<ColumnPredicate> predicate);
312
313
    [[nodiscard]] Status _extract_common_expr_columns(const VExprSPtr& expr);
314
    [[nodiscard]] Status _execute_common_expr(uint16_t* sel_rowid_idx, uint16_t& selected_size,
315
                                              Block* block);
316
    Status _process_common_expr(uint16_t* sel_rowid_idx, uint16_t& selected_size, Block* block);
317
318
    uint16_t _evaluate_common_expr_filter(uint16_t* sel_rowid_idx, uint16_t selected_size,
319
                                          const IColumn::Filter& filter);
320
321
    // Dictionary column should do something to initial.
322
    void _convert_dict_code_for_predicate_if_necessary();
323
324
    void _convert_dict_code_for_predicate_if_necessary_impl(
325
            std::shared_ptr<ColumnPredicate> predicate);
326
327
    bool _check_apply_by_inverted_index(std::shared_ptr<ColumnPredicate> pred);
328
329
    void _output_index_result_column(const VExprContextSPtrs& expr_ctxs, uint16_t* sel_rowid_idx,
330
                                     uint16_t select_size);
331
332
    bool _need_read_data(ColumnId cid);
333
    bool _prune_column(ColumnId cid, MutableColumnPtr& column, size_t num_of_defaults);
334
335
    Status _construct_compound_expr_context();
336
337
    int _compare_short_key_with_seek_block(const RowCursor& key,
338
0
                                           const std::vector<ColumnId>& col_ids) {
339
0
        for (auto cid : col_ids) {
340
0
            auto ord = key.field(cid) <=> (*_seek_block[cid])[0];
341
0
            if (ord != std::strong_ordering::equal) {
342
0
                return ord == std::strong_ordering::less ? -1 : 1;
343
0
            }
344
0
        }
345
0
        return 0;
346
0
    }
347
348
    Status _convert_to_expected_type(const std::vector<ColumnId>& col_ids);
349
350
    bool _no_need_read_key_data(ColumnId cid, MutableColumnPtr& column, size_t nrows_read);
351
    // Side-effect-free eligibility half of _no_need_read_key_data (no column
352
    // fill); shared by the per-batch fill and the G03 engage-time per-column
353
    // proof so the two can never drift.
354
    bool _no_need_read_key_data_eligible(ColumnId cid);
355
356
    bool _has_delete_predicate(ColumnId cid);
357
    bool _can_skip_reading_extra_column(ColumnId cid);
358
359
    bool _can_opt_limit_reads();
360
361
    void _initialize_predicate_results();
362
    bool _check_all_conditions_passed_inverted_index_for_column(ColumnId cid,
363
                                                                bool default_return = false);
364
365
    void _calculate_common_expr_index_exec_status();
366
367
    Status _process_eof(Block* block);
368
369
    void _fill_column_nothing();
370
371
    Status _process_columns(const std::vector<ColumnId>& column_ids, Block* block);
372
373
    // Initialize virtual columns in the block, set all virtual columns in the block to ColumnNothing
374
    void _init_virtual_columns(Block* block);
375
    // Fallback logic for virtual column materialization, materializing all unmaterialized virtual columns through expressions
376
    Status _materialization_of_virtual_column(Block* block);
377
    void _prepare_score_column_materialization();
378
379
    void _init_row_bitmap_by_condition_cache();
380
381
    void _init_segment_prefetchers();
382
383
    class BitmapRangeIterator;
384
    class BackwardBitmapRangeIterator;
385
386
    std::shared_ptr<Segment> _segment;
387
    // read schema from scanner
388
    SchemaSPtr _schema;
389
    // storage type schema related to _schema, since column in segment may be different with type in _schema
390
    std::vector<IndexFieldNameAndTypePair> _storage_name_and_type;
391
    // vector idx -> column iterarator
392
    std::vector<std::unique_ptr<ColumnIterator>> _column_iterators;
393
    std::vector<std::unique_ptr<IndexIterator>> _index_iterators;
394
    // after init(), `_row_bitmap` contains all rowid to scan
395
    roaring::Roaring _row_bitmap;
396
    // an iterator for `_row_bitmap` that can be used to extract row range to scan
397
    std::unique_ptr<BitmapRangeIterator> _range_iter;
398
    // the next rowid to read
399
    rowid_t _cur_rowid;
400
    // members related to lazy materialization read
401
    // --------------------------------------------
402
    // whether lazy materialization read should be used.
403
    bool _lazy_materialization_read;
404
    // columns to read after predicate evaluation and remaining expr execute
405
    std::vector<ColumnId> _non_predicate_columns;
406
    std::set<ColumnId> _common_expr_columns;
407
    // remember the rowids we've read for the current row block.
408
    // could be a local variable of next_batch(), kept here to reuse vector memory
409
    std::vector<rowid_t> _block_rowids;
410
    bool _is_need_vec_eval = false;
411
    bool _is_need_short_eval = false;
412
    bool _is_need_expr_eval = false;
413
414
    std::set<ColumnId> _support_lazy_read_pruned_columns;
415
    bool _enable_prune_nested_column = false;
416
417
    // fields for vectorization execution
418
    std::vector<ColumnId>
419
            _vec_pred_column_ids; // keep columnId of columns for vectorized predicate evaluation
420
    std::vector<ColumnId>
421
            _short_cir_pred_column_ids; // keep columnId of columns for short circuit predicate evaluation
422
    std::vector<bool> _is_pred_column; // columns hold _init segmentIter
423
    std::map<uint32_t, bool> _need_read_data_indices;
424
    std::vector<bool> _is_common_expr_column;
425
    MutableColumns _current_return_columns;
426
    std::vector<std::shared_ptr<ColumnPredicate>> _pre_eval_block_predicate;
427
    std::vector<std::shared_ptr<ColumnPredicate>> _short_cir_eval_predicate;
428
    std::vector<uint32_t> _delete_range_column_ids;
429
    std::vector<uint32_t> _delete_bloom_filter_column_ids;
430
    // when lazy materialization is enabled, segmentIter need to read data at least twice
431
    // first, read predicate columns by various index
432
    // second, read non-predicate columns
433
    // so we need a field to stand for columns first time to read
434
    std::vector<ColumnId> _predicate_column_ids;
435
    std::vector<ColumnId> _common_expr_column_ids;
436
    // Block slot indexes to filter after common expr evaluation. This is not
437
    // tablet column ids because Block::filter_block_internal filters by block
438
    // position.
439
    std::vector<ColumnId> _columns_to_filter;
440
    std::vector<bool> _converted_column_ids;
441
442
    // the actual init process is delayed to the first call to next_batch()
443
    bool _lazy_inited;
444
    bool _inited;
445
446
    StorageReadOptions _opts;
447
    // Adaptive batch size predictor; null when the feature is disabled.
448
    std::unique_ptr<AdaptiveBlockSizePredictor> _block_size_predictor;
449
    // Build the AdaptiveBlockSizePredictor for this segment based on segment footer
450
    // metadata for the projected output columns. Returns nullptr if the feature is
451
    // disabled or the byte budget is non-positive.
452
    std::unique_ptr<AdaptiveBlockSizePredictor> _make_block_size_predictor() const;
453
    // Snapshot of _opts.block_row_max at init time; used as the hard upper bound so that
454
    // dynamic adjustments never exceed the capacity of pre-allocated buffers.
455
    uint32_t _initial_block_row_max = 0;
456
    // make a copy of `_opts.column_predicates` in order to make local changes
457
    std::vector<std::shared_ptr<ColumnPredicate>> _col_predicates;
458
    VExprContextSPtrs _common_expr_ctxs_push_down;
459
    std::set<ColumnId> _not_apply_index_pred;
460
461
    // row schema of the key to seek
462
    // only used in `_get_row_ranges_by_keys`
463
    std::unique_ptr<Schema> _seek_schema;
464
    // used to binary search the rowid for a given key
465
    // only used in `_get_row_ranges_by_keys`
466
    MutableColumns _seek_block;
467
468
    io::FileReaderSPtr _file_reader;
469
470
    // used for compaction, record selectd rowids of current batch
471
    uint16_t _selected_size;
472
    std::vector<uint16_t> _sel_rowid_idx;
473
474
    // Rows already produced by this iterator. Used together with
475
    // _opts.read_limit to compute the remaining per-batch budget.
476
    size_t _rows_returned = 0;
477
478
    std::unique_ptr<ObjectPool> _pool;
479
480
    // used to collect filter information.
481
    std::vector<std::shared_ptr<ColumnPredicate>> _filter_info_id;
482
    bool _record_rowids = false;
483
    int64_t _tablet_id = 0;
484
    std::set<int32_t> _output_columns;
485
486
    std::vector<uint8_t> _ret_flags;
487
488
    /*
489
    * column and column_predicates on it.
490
    * a boolean value to indicate whether the column has been read by the index.
491
    */
492
    std::unordered_map<ColumnId, std::unordered_map<std::shared_ptr<ColumnPredicate>, bool>>
493
            _column_predicate_index_exec_status;
494
495
    /*
496
    * column and common expr on it.
497
    * a boolean value to indicate whether the column has been read by the index.
498
    */
499
    std::unordered_map<ColumnId, std::unordered_map<const VExpr*, bool>>
500
            _common_expr_index_exec_status;
501
502
    /*
503
    * common expr context to slotref map
504
    * slot ref map is used to get slot ref expr by using column id.
505
    */
506
    std::unordered_map<VExprContext*, std::unordered_map<ColumnId, VExpr*>>
507
            _common_expr_to_slotref_map;
508
509
    ScoreRuntimeSPtr _score_runtime;
510
511
    std::shared_ptr<segment_v2::AnnTopNRuntime> _ann_topn_runtime;
512
513
    // cid to virtual column expr
514
    std::map<ColumnId, VExprContextSPtr> _virtual_column_exprs;
515
516
    IndexQueryContextPtr _index_query_context;
517
518
    // G03 count-emission shortcut state (see count_on_index_fastpath.h).
519
    // _count_fastpath_hit: the reader answered the single MATCH predicate with
520
    // a fabricated count bitmap (captured from the G02 handshake reply).
521
    // _count_emit_shortcut: engaged at the end of _lazy_init when
522
    // count_emit_shortcut_safe holds; every subsequent batch is emitted by
523
    // _emit_count_shortcut_batch from _count_emit_rows_remaining (initialized
524
    // to the post-apply _row_bitmap cardinality) without touching the row
525
    // bitmap iterator.
526
    bool _count_fastpath_hit = false;
527
    bool _count_emit_shortcut = false;
528
    uint64_t _count_emit_rows_remaining = 0;
529
    // Batch size for shortcut emission: VStatisticsIterator's
530
    // MAX_ROW_SIZE_IN_COUNT, the largest default-rows block shape already
531
    // proven through every consumer above the segment iterator by the plain
532
    // COUNT pushdown (rowset reader, collect iterator, block reader, scanner).
533
    static constexpr uint64_t kCountEmitBatchRows = 65535;
534
535
    // key is column uid, value is the sparse column cache
536
    std::unordered_map<int32_t, PathToBinaryColumnCacheUPtr> _variant_sparse_column_cache;
537
538
    bool _find_condition_cache = false;
539
    std::shared_ptr<std::vector<bool>> _condition_cache;
540
    static constexpr int CONDITION_CACHE_OFFSET = 2048;
541
};
542
543
} // namespace segment_v2
544
} // namespace doris