Coverage Report

Created: 2026-07-19 19:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vexpr_context.cpp
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
#include "exprs/vexpr_context.h"
19
20
#include <algorithm>
21
#include <cstdint>
22
#include <memory>
23
#include <string>
24
#include <utility>
25
26
#include "common/compiler_util.h" // IWYU pragma: keep
27
#include "common/exception.h"
28
#include "common/logging.h"
29
#include "common/status.h"
30
#include "core/block/column_numbers.h"
31
#include "core/block/column_with_type_and_name.h"
32
#include "core/block/columns_with_type_and_name.h"
33
#include "core/column/column.h"
34
#include "core/column/column_const.h"
35
#include "exec/common/util.hpp"
36
#include "exprs/function_context.h"
37
#include "exprs/lambda_function/lambda_execution_context.h"
38
#include "exprs/vexpr.h"
39
#include "runtime/runtime_state.h"
40
#include "runtime/thread_context.h"
41
#include "storage/olap_common.h"
42
#include "storage/segment/column_reader.h"
43
#include "util/simd/bits.h"
44
45
namespace doris {
46
class RowDescriptor;
47
} // namespace doris
48
49
namespace doris {
50
51
656k
VExprContext::VExprContext(VExprSPtr expr) : _root(std::move(expr)) {}
52
53
656k
VExprContext::~VExprContext() {
54
    // In runtime filter, only create expr context to get expr root, will not call
55
    // prepare or open, so that it is not need to call close. And call close may core
56
    // because the function context in expr is not set.
57
656k
    if (!_prepared || !_opened) {
58
142k
        return;
59
142k
    }
60
514k
    try {
61
514k
        close();
62
514k
    } catch (const Exception& e) {
63
0
        LOG(WARNING) << "Exception occurs when expr context deconstruct: " << e.to_string();
64
0
    }
65
514k
}
66
67
57
LambdaExecutionContext& VExprContext::lambda_execution_context() {
68
57
    if (!_lambda_execution_context) {
69
11
        _lambda_execution_context = std::make_unique<LambdaExecutionContext>();
70
11
    }
71
57
    return *_lambda_execution_context;
72
57
}
73
74
189k
Status VExprContext::execute(Block* block, int* result_column_id) {
75
189k
    Status st;
76
189k
    RETURN_IF_CATCH_EXCEPTION({
77
189k
        st = _root->execute(this, block, result_column_id);
78
189k
        _last_result_column_id = *result_column_id;
79
        // We should first check the status, as some expressions might incorrectly set result_column_id, even if the st is not ok.
80
189k
        if (st.ok() && _last_result_column_id != -1) {
81
189k
            block->get_by_position(*result_column_id).column->sanity_check();
82
189k
            RETURN_IF_ERROR(
83
189k
                    block->get_by_position(*result_column_id).check_type_and_column_match());
84
189k
        }
85
189k
    });
86
189k
    return st;
87
189k
}
88
89
286
Status VExprContext::execute(const Block* block, ColumnPtr& result_column) {
90
286
    Status st;
91
286
    RETURN_IF_CATCH_EXCEPTION(
92
286
            { st = _root->execute_column(this, block, nullptr, block->rows(), result_column); });
93
286
    return st;
94
286
}
95
96
19
Status VExprContext::execute(const Block* block, ColumnWithTypeAndName& result_data) {
97
19
    Status st;
98
19
    ColumnPtr result_column;
99
19
    RETURN_IF_CATCH_EXCEPTION(
100
19
            { st = _root->execute_column(this, block, nullptr, block->rows(), result_column); });
101
19
    RETURN_IF_ERROR(st);
102
19
    result_data.column = result_column;
103
19
    result_data.type = execute_type(block);
104
19
    result_data.name = _root->expr_name();
105
19
    return Status::OK();
106
19
}
107
108
54
DataTypePtr VExprContext::execute_type(const Block* block) {
109
54
    return _root->execute_type(block);
110
54
}
111
112
30
Status VExprContext::execute_const_expr(ColumnWithTypeAndName& result) {
113
30
    Status st;
114
30
    RETURN_IF_CATCH_EXCEPTION(
115
30
            { st = _root->execute_column(this, nullptr, nullptr, 1, result.column); });
116
30
    RETURN_IF_ERROR(st);
117
30
    result.type = _root->execute_type(nullptr);
118
30
    result.name = _root->expr_name();
119
30
    return Status::OK();
120
30
}
121
122
57
[[nodiscard]] const std::string& VExprContext::expr_name() const {
123
57
    return _root->expr_name();
124
57
}
125
126
0
bool VExprContext::is_blockable() const {
127
0
    return _root->is_blockable();
128
0
}
129
130
258k
Status VExprContext::prepare(RuntimeState* state, const RowDescriptor& row_desc) {
131
258k
    _prepared = true;
132
258k
    Status st;
133
258k
    RETURN_IF_CATCH_EXCEPTION({ st = _root->prepare(state, row_desc, this); });
134
258k
    return st;
135
258k
}
136
137
258k
Status VExprContext::open(RuntimeState* state) {
138
258k
    DCHECK(_prepared);
139
258k
    if (_opened) {
140
14
        return Status::OK();
141
14
    }
142
258k
    _opened = true;
143
    // Fragment-local state is only initialized for original contexts. Clones inherit the
144
    // original's fragment state and only need to have thread-local state initialized.
145
258k
    FunctionContext::FunctionStateScope scope =
146
258k
            _is_clone ? FunctionContext::THREAD_LOCAL : FunctionContext::FRAGMENT_LOCAL;
147
258k
    Status st;
148
258k
    RETURN_IF_CATCH_EXCEPTION({ st = _root->open(state, this, scope); });
149
258k
    return st;
150
258k
}
151
152
514k
void VExprContext::close() {
153
    // Sometimes expr context may not have a root, then it need not call close
154
514k
    if (_root == nullptr) {
155
0
        return;
156
0
    }
157
514k
    FunctionContext::FunctionStateScope scope =
158
514k
            _is_clone ? FunctionContext::THREAD_LOCAL : FunctionContext::FRAGMENT_LOCAL;
159
514k
    _root->close(this, scope);
160
514k
}
161
162
254k
Status VExprContext::clone(RuntimeState* state, VExprContextSPtr& new_ctx) {
163
254k
    DCHECK(_prepared) << "expr context not prepared";
164
254k
    DCHECK(_opened);
165
254k
    DCHECK(new_ctx.get() == nullptr);
166
167
254k
    new_ctx = std::make_shared<VExprContext>(_root);
168
254k
    for (auto& _fn_context : _fn_contexts) {
169
43
        new_ctx->_fn_contexts.push_back(_fn_context->clone());
170
43
    }
171
172
254k
    new_ctx->_is_clone = true;
173
254k
    new_ctx->_prepared = true;
174
254k
    new_ctx->_opened = true;
175
    // segment_v2::AnnRangeSearchRuntime should be cloned as well.
176
    // The object of segment_v2::AnnRangeSearchRuntime is not shared by threads.
177
254k
    new_ctx->_ann_range_search_runtime = this->_ann_range_search_runtime;
178
179
254k
    return _root->open(state, new_ctx.get(), FunctionContext::THREAD_LOCAL);
180
254k
}
181
182
0
void VExprContext::clone_fn_contexts(VExprContext* other) {
183
0
    for (auto& _fn_context : _fn_contexts) {
184
0
        other->_fn_contexts.push_back(_fn_context->clone());
185
0
    }
186
0
}
187
188
int VExprContext::register_function_context(RuntimeState* state, const DataTypePtr& return_type,
189
205
                                            const std::vector<DataTypePtr>& arg_types) {
190
205
    _fn_contexts.push_back(FunctionContext::create_context(state, return_type, arg_types));
191
205
    _fn_contexts.back()->set_check_overflow_for_decimal(state->check_overflow_for_decimal());
192
205
    _fn_contexts.back()->set_enable_strict_mode(state->enable_strict_mode());
193
205
    return static_cast<int>(_fn_contexts.size()) - 1;
194
205
}
195
196
18
Status VExprContext::evaluate_inverted_index(uint32_t segment_num_rows) {
197
18
    Status st;
198
18
    RETURN_IF_CATCH_EXCEPTION({ st = _root->evaluate_inverted_index(this, segment_num_rows); });
199
18
    return st;
200
18
}
201
202
ZoneMapFilterResult VExprContext::evaluate_zonemap_filter(const VExprContextSPtrs& conjuncts,
203
261
                                                          const ZoneMapEvalContext& ctx) {
204
284
    for (const auto& conjunct : conjuncts) {
205
284
        DORIS_CHECK(conjunct != nullptr);
206
284
        const auto& root = conjunct->root();
207
284
        DORIS_CHECK(root != nullptr);
208
284
        if (!root->can_evaluate_zonemap_filter()) {
209
14
            continue;
210
14
        }
211
270
        if (root->evaluate_zonemap_filter(ctx) == ZoneMapFilterResult::kNoMatch) {
212
103
            return ZoneMapFilterResult::kNoMatch;
213
103
        }
214
270
    }
215
158
    return ZoneMapFilterResult::kMayMatch;
216
261
}
217
218
ZoneMapFilterResult VExprContext::evaluate_dictionary_filter(const VExprContextSPtrs& conjuncts,
219
80
                                                             const DictionaryEvalContext& ctx) {
220
80
    for (const auto& conjunct : conjuncts) {
221
80
        DORIS_CHECK(conjunct != nullptr);
222
80
        const auto& root = conjunct->root();
223
80
        DORIS_CHECK(root != nullptr);
224
80
        if (!root->can_evaluate_dictionary_filter()) {
225
0
            continue;
226
0
        }
227
80
        if (root->evaluate_dictionary_filter(ctx) == ZoneMapFilterResult::kNoMatch) {
228
47
            return ZoneMapFilterResult::kNoMatch;
229
47
        }
230
80
    }
231
33
    return ZoneMapFilterResult::kMayMatch;
232
80
}
233
234
ZoneMapFilterResult VExprContext::evaluate_bloom_filter(const VExprContextSPtrs& conjuncts,
235
17
                                                        const BloomFilterEvalContext& ctx) {
236
17
    for (const auto& conjunct : conjuncts) {
237
17
        DORIS_CHECK(conjunct != nullptr);
238
17
        const auto& root = conjunct->root();
239
17
        DORIS_CHECK(root != nullptr);
240
17
        if (!root->can_evaluate_bloom_filter()) {
241
0
            continue;
242
0
        }
243
17
        if (root->evaluate_bloom_filter(ctx) == ZoneMapFilterResult::kNoMatch) {
244
8
            return ZoneMapFilterResult::kNoMatch;
245
8
        }
246
17
    }
247
9
    return ZoneMapFilterResult::kMayMatch;
248
17
}
249
250
18
bool VExprContext::all_expr_inverted_index_evaluated() {
251
18
    return _index_context->has_index_result_for_expr(_root.get());
252
18
}
253
254
0
Status VExprContext::filter_block(VExprContext* vexpr_ctx, Block* block) {
255
0
    if (vexpr_ctx == nullptr || block->rows() == 0) {
256
0
        return Status::OK();
257
0
    }
258
0
    ColumnPtr filter_column;
259
0
    RETURN_IF_ERROR(vexpr_ctx->execute(block, filter_column));
260
0
    size_t filter_column_id = block->columns();
261
0
    block->insert({filter_column, vexpr_ctx->execute_type(block), "filter_column"});
262
0
    vexpr_ctx->_memory_usage = filter_column->allocated_bytes();
263
0
    return Block::filter_block(block, filter_column_id, filter_column_id);
264
0
}
265
266
Status VExprContext::filter_block(const VExprContextSPtrs& expr_contexts, Block* block,
267
1.06k
                                  size_t column_to_keep) {
268
1.06k
    if (expr_contexts.empty() || block->rows() == 0) {
269
1.05k
        return Status::OK();
270
1.05k
    }
271
272
11
    ColumnNumbers columns_to_filter(column_to_keep);
273
11
    std::iota(columns_to_filter.begin(), columns_to_filter.end(), 0);
274
275
11
    return execute_conjuncts_and_filter_block(expr_contexts, block, columns_to_filter,
276
11
                                              static_cast<int>(column_to_keep));
277
1.06k
}
278
279
Status VExprContext::execute_conjuncts(const VExprContextSPtrs& ctxs,
280
                                       const std::vector<IColumn::Filter*>* filters, Block* block,
281
26
                                       IColumn::Filter* result_filter, bool* can_filter_all) {
282
26
    return execute_conjuncts(ctxs, filters, false, block, result_filter, can_filter_all);
283
26
}
284
285
Status VExprContext::execute_filter(const Block* block, uint8_t* __restrict result_filter_data,
286
291
                                    size_t rows, bool accept_null, bool* can_filter_all) {
287
291
    return _root->execute_filter(this, block, result_filter_data, rows, accept_null,
288
291
                                 can_filter_all);
289
291
}
290
291
Status VExprContext::execute_conjuncts(const VExprContextSPtrs& ctxs,
292
                                       const std::vector<IColumn::Filter*>* filters,
293
                                       bool accept_null, const Block* block,
294
50
                                       IColumn::Filter* result_filter, bool* can_filter_all) {
295
50
    size_t rows = block->rows();
296
50
    DCHECK_EQ(result_filter->size(), rows);
297
50
    *can_filter_all = false;
298
50
    auto* __restrict result_filter_data = result_filter->data();
299
74
    for (const auto& ctx : ctxs) {
300
74
        RETURN_IF_ERROR(
301
74
                ctx->execute_filter(block, result_filter_data, rows, accept_null, can_filter_all));
302
74
        if (*can_filter_all) {
303
3
            return Status::OK();
304
3
        }
305
74
    }
306
47
    if (filters != nullptr) {
307
22
        for (auto* filter : *filters) {
308
0
            auto* __restrict filter_data = filter->data();
309
0
            const size_t size = filter->size();
310
0
            for (size_t i = 0; i < size; ++i) {
311
0
                result_filter_data[i] &= filter_data[i];
312
0
            }
313
0
            if (memchr(result_filter_data, 0x1, size) == nullptr) {
314
0
                *can_filter_all = true;
315
0
                return Status::OK();
316
0
            }
317
0
        }
318
22
    }
319
47
    return Status::OK();
320
47
}
321
322
Status VExprContext::execute_conjuncts(const VExprContextSPtrs& conjuncts, const Block* block,
323
6
                                       ColumnUInt8& null_map, IColumn::Filter& filter) {
324
6
    const auto& rows = block->rows();
325
6
    if (rows == 0) {
326
0
        return Status::OK();
327
0
    }
328
6
    if (null_map.size() != rows) {
329
0
        return Status::InternalError("null_map.size()!=rows, null_map.size()={}, rows={}",
330
0
                                     null_map.size(), rows);
331
0
    }
332
333
6
    auto* final_null_map = null_map.get_data().data();
334
6
    auto* final_filter_ptr = filter.data();
335
336
6
    for (const auto& conjunct : conjuncts) {
337
4
        ColumnPtr result_column;
338
4
        RETURN_IF_ERROR(conjunct->execute(block, result_column));
339
4
        auto [filter_column, is_const] = unpack_if_const(result_column);
340
4
        const auto* nullable_column = assert_cast<const ColumnNullable*>(filter_column.get());
341
4
        if (!is_const) {
342
4
            const ColumnPtr& nested_column = nullable_column->get_nested_column_ptr();
343
4
            const IColumn::Filter& result =
344
4
                    assert_cast<const ColumnUInt8&>(*nested_column).get_data();
345
4
            const auto* __restrict filter_data = result.data();
346
4
            const auto* __restrict null_map_data = nullable_column->get_null_map_data().data();
347
4
            DCHECK_EQ(rows, nullable_column->size());
348
349
32
            for (size_t i = 0; i != rows; ++i) {
350
                // null and null    => null
351
                // null and true    => null
352
                // null and false   => false
353
28
                final_null_map[i] = (final_null_map[i] & (null_map_data[i] | filter_data[i])) |
354
28
                                    (null_map_data[i] & (final_null_map[i] | final_filter_ptr[i]));
355
28
                final_filter_ptr[i] = final_filter_ptr[i] & filter_data[i];
356
28
            }
357
4
        } else {
358
0
            bool filter_data = nullable_column->get_bool(0);
359
0
            bool null_map_data = nullable_column->is_null_at(0);
360
0
            for (size_t i = 0; i != rows; ++i) {
361
                // null and null    => null
362
                // null and true    => null
363
                // null and false   => false
364
0
                final_null_map[i] = (final_null_map[i] & (null_map_data | filter_data)) |
365
0
                                    (null_map_data & (final_null_map[i] | final_filter_ptr[i]));
366
0
                final_filter_ptr[i] = final_filter_ptr[i] & filter_data;
367
0
            }
368
0
        }
369
4
    }
370
6
    return Status::OK();
371
6
}
372
373
// TODO Performance Optimization
374
// need exception safety
375
Status VExprContext::execute_conjuncts_and_filter_block(const VExprContextSPtrs& ctxs, Block* block,
376
                                                        std::vector<uint32_t>& columns_to_filter,
377
11
                                                        int column_to_keep) {
378
11
    IColumn::Filter result_filter(block->rows(), 1);
379
11
    bool can_filter_all;
380
381
11
    _reset_memory_usage(ctxs);
382
383
11
    RETURN_IF_ERROR(
384
11
            execute_conjuncts(ctxs, nullptr, false, block, &result_filter, &can_filter_all));
385
386
    // Accumulate the usage of `result_filter` into the first context.
387
11
    if (!ctxs.empty()) {
388
11
        ctxs[0]->_memory_usage += result_filter.allocated_bytes();
389
11
    }
390
11
    if (can_filter_all) {
391
3
        for (auto& col : columns_to_filter) {
392
3
            auto& column = block->get_by_position(col).column;
393
3
            if (column->is_exclusive()) {
394
3
                column->assert_mutable()->clear();
395
3
            } else {
396
0
                column = column->clone_empty();
397
0
            }
398
3
        }
399
10
    } else {
400
10
        try {
401
10
            Block::filter_block_internal(block, columns_to_filter, result_filter);
402
10
        } catch (const Exception& e) {
403
0
            std::string str;
404
0
            for (auto ctx : ctxs) {
405
0
                if (str.length()) {
406
0
                    str += ",";
407
0
                }
408
0
                str += ctx->root()->debug_string();
409
0
            }
410
411
0
            return Status::InternalError(
412
0
                    "filter_block_internal meet exception, exprs=[{}], exception={}", str,
413
0
                    e.what());
414
0
        }
415
10
    }
416
11
    Block::erase_useless_column(block, column_to_keep);
417
11
    return Status::OK();
418
11
}
419
420
Status VExprContext::execute_conjuncts_and_filter_block(const VExprContextSPtrs& ctxs, Block* block,
421
                                                        std::vector<uint32_t>& columns_to_filter,
422
                                                        int column_to_keep,
423
13
                                                        IColumn::Filter& filter) {
424
13
    _reset_memory_usage(ctxs);
425
13
    filter.resize_fill(block->rows(), 1);
426
13
    bool can_filter_all;
427
13
    RETURN_IF_ERROR(execute_conjuncts(ctxs, nullptr, false, block, &filter, &can_filter_all));
428
429
    // Accumulate the usage of `result_filter` into the first context.
430
13
    if (!ctxs.empty()) {
431
13
        ctxs[0]->_memory_usage += filter.allocated_bytes();
432
13
    }
433
13
    if (can_filter_all) {
434
3
        for (auto& col : columns_to_filter) {
435
3
            auto& column = block->get_by_position(col).column;
436
3
            if (column->is_exclusive()) {
437
3
                column->assert_mutable()->clear();
438
3
            } else {
439
0
                column = column->clone_empty();
440
0
            }
441
3
        }
442
12
    } else {
443
12
        RETURN_IF_CATCH_EXCEPTION(Block::filter_block_internal(block, columns_to_filter, filter));
444
12
    }
445
446
13
    Block::erase_useless_column(block, column_to_keep);
447
13
    return Status::OK();
448
13
}
449
450
// do_projection: for some query(e.g. in MultiCastDataStreamerSourceOperator::get_block()),
451
// output_vexpr_ctxs will output the same column more than once, and if the output_block
452
// is mem-reused later, it will trigger DCHECK_EQ(d.column->use_count(), 1) failure when
453
// doing Block::clear_column_data, set do_projection to true to copy the column data to
454
// avoid this problem.
455
Status VExprContext::get_output_block_after_execute_exprs(
456
        const VExprContextSPtrs& output_vexpr_ctxs, const Block& input_block, Block* output_block,
457
5
        bool do_projection) {
458
5
    auto rows = input_block.rows();
459
5
    ColumnsWithTypeAndName result_columns;
460
5
    _reset_memory_usage(output_vexpr_ctxs);
461
462
28
    for (const auto& vexpr_ctx : output_vexpr_ctxs) {
463
28
        ColumnPtr result_column;
464
28
        RETURN_IF_ERROR(vexpr_ctx->execute(&input_block, result_column));
465
466
28
        auto type = vexpr_ctx->execute_type(&input_block);
467
28
        const auto& name = vexpr_ctx->expr_name();
468
469
28
        vexpr_ctx->_memory_usage += result_column->allocated_bytes();
470
28
        if (do_projection) {
471
0
            result_columns.emplace_back(result_column->clone_resized(rows), type, name);
472
473
28
        } else {
474
28
            result_columns.emplace_back(result_column, type, name);
475
28
        }
476
28
    }
477
5
    *output_block = {result_columns};
478
5
    return Status::OK();
479
5
}
480
481
29
void VExprContext::_reset_memory_usage(const VExprContextSPtrs& contexts) {
482
29
    std::for_each(contexts.begin(), contexts.end(),
483
52
                  [](auto&& context) { context->_memory_usage = 0; });
484
29
}
485
486
7
void VExprContext::prepare_ann_range_search(const doris::VectorSearchUserParams& params) {
487
7
    if (_root == nullptr) {
488
0
        return;
489
0
    }
490
491
7
    _root->prepare_ann_range_search(params, _ann_range_search_runtime, _suitable_for_ann_index);
492
7
    VLOG_DEBUG << fmt::format("Prepare ann range search result {}, _suitable_for_ann_index {}",
493
0
                              this->_ann_range_search_runtime.to_string(),
494
0
                              this->_suitable_for_ann_index);
495
7
    return;
496
7
}
497
498
Status VExprContext::evaluate_ann_range_search(
499
        const std::vector<std::unique_ptr<segment_v2::IndexIterator>>& cid_to_index_iterators,
500
        const std::vector<ColumnId>& idx_to_cid,
501
        const std::vector<std::unique_ptr<segment_v2::ColumnIterator>>& column_iterators,
502
        const std::unordered_map<VExprContext*, std::unordered_map<ColumnId, VExpr*>>&
503
                common_expr_to_slotref_map,
504
        size_t rows_of_segment, roaring::Roaring& row_bitmap,
505
        segment_v2::AnnIndexStats& ann_index_stats, bool enable_result_cache,
506
24
        bool* ann_range_search_executed) {
507
24
    if (ann_range_search_executed != nullptr) {
508
23
        *ann_range_search_executed = false;
509
23
    }
510
24
    if (_root == nullptr) {
511
0
        return Status::OK();
512
0
    }
513
514
24
    AnnRangeSearchEvaluationResult evaluation_result;
515
24
    RETURN_IF_ERROR(_root->evaluate_ann_range_search(
516
24
            _ann_range_search_runtime, cid_to_index_iterators, idx_to_cid, column_iterators,
517
24
            rows_of_segment, row_bitmap, ann_index_stats, enable_result_cache, evaluation_result));
518
519
23
    if (!evaluation_result.executed) {
520
19
        return Status::OK();
521
19
    }
522
4
    if (ann_range_search_executed != nullptr) {
523
4
        *ann_range_search_executed = true;
524
4
    }
525
526
4
    DCHECK(_index_context != nullptr);
527
4
    _index_context->set_index_result_for_expr(
528
4
            _root.get(),
529
4
            segment_v2::InvertedIndexResultBitmap(std::make_shared<roaring::Roaring>(row_bitmap),
530
4
                                                  std::make_shared<roaring::Roaring>()));
531
532
4
    if (!evaluation_result.dist_fulfilled) {
533
        // Do not perform index scan in this case.
534
2
        return Status::OK();
535
2
    }
536
537
4
    DCHECK_LT(_ann_range_search_runtime.src_col_idx, idx_to_cid.size());
538
2
    const auto src_col_idx = cast_set<int>(_ann_range_search_runtime.src_col_idx);
539
2
    const auto src_col_key = cast_set<ColumnId>(_ann_range_search_runtime.src_col_idx);
540
2
    auto slot_ref_map_it = common_expr_to_slotref_map.find(this);
541
2
    if (slot_ref_map_it == common_expr_to_slotref_map.end()) {
542
1
        return Status::OK();
543
1
    }
544
1
    auto& slot_ref_map = slot_ref_map_it->second;
545
1
    auto slot_ref_it = slot_ref_map.find(src_col_key);
546
1
    if (slot_ref_it == slot_ref_map.end()) {
547
0
        return Status::OK();
548
0
    }
549
1
    const VExpr* slot_ref_expr_addr = slot_ref_it->second;
550
1
    _index_context->set_true_for_index_status(slot_ref_expr_addr, src_col_idx);
551
552
1
    VLOG_DEBUG << fmt::format(
553
0
            "Evaluate ann range search for expr {}, src_col_idx {}, cid {}, row_bitmap "
554
0
            "cardinality {}",
555
0
            _root->debug_string(), src_col_idx, idx_to_cid[_ann_range_search_runtime.src_col_idx],
556
0
            row_bitmap.cardinality());
557
1
    return Status::OK();
558
1
}
559
560
13
uint64_t VExprContext::get_digest(uint64_t seed) const {
561
13
    return _root->get_digest(seed);
562
13
}
563
564
4
double VExprContext::execute_cost() const {
565
4
    if (_root == nullptr) {
566
        // When there is no expression root, treat the cost as a base value.
567
        // This avoids null dereferences while keeping a deterministic cost.
568
0
        return 0.0;
569
0
    }
570
4
    return _root->execute_cost();
571
4
}
572
573
} // namespace doris