|
29 | 29 | #include "core/block/columns_with_type_and_name.h" |
30 | 30 | #include "core/column/column.h" |
31 | 31 | #include "core/column/column_const.h" |
| 32 | +#include "exec/common/util.hpp" |
32 | 33 | #include "exprs/function_context.h" |
33 | 34 | #include "exprs/vexpr.h" |
34 | 35 | #include "runtime/runtime_state.h" |
@@ -440,41 +441,57 @@ Status VExprContext::evaluate_ann_range_search( |
440 | 441 | const std::unordered_map<VExprContext*, std::unordered_map<ColumnId, VExpr*>>& |
441 | 442 | common_expr_to_slotref_map, |
442 | 443 | roaring::Roaring& row_bitmap, segment_v2::AnnIndexStats& ann_index_stats, |
443 | | - bool enable_result_cache) { |
| 444 | + bool enable_result_cache, bool* ann_range_search_executed) { |
| 445 | + if (ann_range_search_executed != nullptr) { |
| 446 | + *ann_range_search_executed = false; |
| 447 | + } |
444 | 448 | if (_root == nullptr) { |
445 | 449 | return Status::OK(); |
446 | 450 | } |
447 | 451 |
|
| 452 | + AnnRangeSearchEvaluationResult evaluation_result; |
448 | 453 | RETURN_IF_ERROR(_root->evaluate_ann_range_search( |
449 | 454 | _ann_range_search_runtime, cid_to_index_iterators, idx_to_cid, column_iterators, |
450 | | - row_bitmap, ann_index_stats, enable_result_cache)); |
| 455 | + row_bitmap, ann_index_stats, enable_result_cache, evaluation_result)); |
451 | 456 |
|
452 | | - if (!_root->ann_range_search_executedd()) { |
| 457 | + if (!evaluation_result.executed) { |
453 | 458 | return Status::OK(); |
454 | 459 | } |
| 460 | + if (ann_range_search_executed != nullptr) { |
| 461 | + *ann_range_search_executed = true; |
| 462 | + } |
| 463 | + |
| 464 | + DCHECK(_index_context != nullptr); |
| 465 | + _index_context->set_index_result_for_expr( |
| 466 | + _root.get(), |
| 467 | + segment_v2::InvertedIndexResultBitmap(std::make_shared<roaring::Roaring>(row_bitmap), |
| 468 | + std::make_shared<roaring::Roaring>())); |
455 | 469 |
|
456 | | - if (!_root->ann_dist_is_fulfilled()) { |
| 470 | + if (!evaluation_result.dist_fulfilled) { |
457 | 471 | // Do not perform index scan in this case. |
458 | 472 | return Status::OK(); |
459 | 473 | } |
460 | 474 |
|
461 | | - auto src_col_idx = _ann_range_search_runtime.src_col_idx; |
| 475 | + DCHECK_LT(_ann_range_search_runtime.src_col_idx, idx_to_cid.size()); |
| 476 | + const auto src_col_idx = cast_set<int>(_ann_range_search_runtime.src_col_idx); |
| 477 | + const auto src_col_key = cast_set<ColumnId>(_ann_range_search_runtime.src_col_idx); |
462 | 478 | auto slot_ref_map_it = common_expr_to_slotref_map.find(this); |
463 | 479 | if (slot_ref_map_it == common_expr_to_slotref_map.end()) { |
464 | 480 | return Status::OK(); |
465 | 481 | } |
466 | 482 | auto& slot_ref_map = slot_ref_map_it->second; |
467 | | - ColumnId cid = idx_to_cid[src_col_idx]; |
468 | | - if (slot_ref_map.find(cid) == slot_ref_map.end()) { |
| 483 | + auto slot_ref_it = slot_ref_map.find(src_col_key); |
| 484 | + if (slot_ref_it == slot_ref_map.end()) { |
469 | 485 | return Status::OK(); |
470 | 486 | } |
471 | | - const VExpr* slot_ref_expr_addr = slot_ref_map.find(cid)->second; |
472 | | - _index_context->set_true_for_index_status(slot_ref_expr_addr, idx_to_cid[cid]); |
| 487 | + const VExpr* slot_ref_expr_addr = slot_ref_it->second; |
| 488 | + _index_context->set_true_for_index_status(slot_ref_expr_addr, src_col_idx); |
473 | 489 |
|
474 | 490 | VLOG_DEBUG << fmt::format( |
475 | 491 | "Evaluate ann range search for expr {}, src_col_idx {}, cid {}, row_bitmap " |
476 | 492 | "cardinality {}", |
477 | | - _root->debug_string(), src_col_idx, cid, row_bitmap.cardinality()); |
| 493 | + _root->debug_string(), src_col_idx, idx_to_cid[_ann_range_search_runtime.src_col_idx], |
| 494 | + row_bitmap.cardinality()); |
478 | 495 | return Status::OK(); |
479 | 496 | } |
480 | 497 |
|
|
0 commit comments