diff --git a/be/src/vec/exprs/vcompound_pred.h b/be/src/vec/exprs/vcompound_pred.h index faed6788ba34ac..9e39533a7aef32 100644 --- a/be/src/vec/exprs/vcompound_pred.h +++ b/be/src/vec/exprs/vcompound_pred.h @@ -144,15 +144,13 @@ class VCompoundPred : public VectorizedFnCall { } if (all_pass && !res.is_empty()) { - // set fast_execute when expr evaluated by inverted index correctly - _can_fast_execute = true; context->get_inverted_index_context()->set_inverted_index_result_for_expr(this, res); } return Status::OK(); } Status execute(VExprContext* context, Block* block, int* result_column_id) override { - if (_can_fast_execute && fast_execute(context, block, result_column_id)) { + if (fast_execute(context, block, result_column_id)) { return Status::OK(); } if (children().size() == 1 || !_all_child_is_compound_and_not_const()) { diff --git a/be/src/vec/exprs/vectorized_fn_call.cpp b/be/src/vec/exprs/vectorized_fn_call.cpp index 097be4abb72a93..569ab7dbc21ad3 100644 --- a/be/src/vec/exprs/vectorized_fn_call.cpp +++ b/be/src/vec/exprs/vectorized_fn_call.cpp @@ -144,7 +144,7 @@ Status VectorizedFnCall::_do_execute(doris::vectorized::VExprContext* context, if (is_const_and_have_executed()) { // const have executed in open function return get_result_from_const(block, _expr_name, result_column_id); } - if (_can_fast_execute && fast_execute(context, block, result_column_id)) { + if (fast_execute(context, block, result_column_id)) { return Status::OK(); } DBUG_EXECUTE_IF("VectorizedFnCall.must_in_slow_path", { diff --git a/be/src/vec/exprs/vexpr.cpp b/be/src/vec/exprs/vexpr.cpp index f026ff0617aea3..6f4ac281c5ae5a 100644 --- a/be/src/vec/exprs/vexpr.cpp +++ b/be/src/vec/exprs/vexpr.cpp @@ -716,8 +716,6 @@ Status VExpr::_evaluate_inverted_index(VExprContext* context, const FunctionBase for (int column_id : column_ids) { index_context->set_true_for_inverted_index_status(this, column_id); } - // set fast_execute when expr evaluated by inverted index correctly - _can_fast_execute = true; } return Status::OK(); } diff --git a/be/src/vec/exprs/vexpr.h b/be/src/vec/exprs/vexpr.h index 2978e6776921df..51f3c2b2523639 100644 --- a/be/src/vec/exprs/vexpr.h +++ b/be/src/vec/exprs/vexpr.h @@ -308,7 +308,6 @@ class VExpr { // ensuring uniqueness during index traversal uint32_t _index_unique_id = 0; - bool _can_fast_execute = false; bool _enable_inverted_index_query = true; uint32_t _in_list_value_count_threshold = 10; }; diff --git a/be/src/vec/exprs/vin_predicate.cpp b/be/src/vec/exprs/vin_predicate.cpp index 65c8a3e693bf8e..727d7ea54a3786 100644 --- a/be/src/vec/exprs/vin_predicate.cpp +++ b/be/src/vec/exprs/vin_predicate.cpp @@ -95,6 +95,8 @@ Status VInPredicate::open(RuntimeState* state, VExprContext* context, if (scope == FunctionContext::FRAGMENT_LOCAL) { RETURN_IF_ERROR(VExpr::get_const_col(context, nullptr)); } + _is_args_all_constant = std::all_of(_children.begin() + 1, _children.end(), + [](const VExprSPtr& expr) { return expr->is_constant(); }); _open_finished = true; return Status::OK(); } @@ -113,13 +115,18 @@ Status VInPredicate::execute(VExprContext* context, Block* block, int* result_co if (is_const_and_have_executed()) { // const have execute in open function return get_result_from_const(block, _expr_name, result_column_id); } - if (_can_fast_execute && fast_execute(context, block, result_column_id)) { + if (fast_execute(context, block, result_column_id)) { return Status::OK(); } DCHECK(_open_finished || _getting_const_col); - // TODO: not execute const expr again, but use the const column in function context - doris::vectorized::ColumnNumbers arguments(_children.size()); - for (int i = 0; i < _children.size(); ++i) { + + // This is an optimization. For expressions like colA IN (1, 2, 3, 4), + // where all values inside the IN clause are constants, + // a hash set is created during open, and it will not be accessed again during execute + // Here, _children[0] is colA + const size_t args_size = _is_args_all_constant ? 1 : _children.size(); + doris::vectorized::ColumnNumbers arguments(args_size); + for (int i = 0; i < args_size; ++i) { int column_id = -1; RETURN_IF_ERROR(_children[i]->execute(context, block, &column_id)); arguments[i] = column_id; diff --git a/be/src/vec/exprs/vin_predicate.h b/be/src/vec/exprs/vin_predicate.h index 4d227510b910ce..3d3846427d6338 100644 --- a/be/src/vec/exprs/vin_predicate.h +++ b/be/src/vec/exprs/vin_predicate.h @@ -62,5 +62,6 @@ class VInPredicate final : public VExpr { const bool _is_not_in; static const constexpr char* function_name = "in"; + bool _is_args_all_constant = false; }; } // namespace doris::vectorized \ No newline at end of file diff --git a/be/src/vec/exprs/vmatch_predicate.cpp b/be/src/vec/exprs/vmatch_predicate.cpp index 4aedb6fe16a070..1025fd5bad7fb6 100644 --- a/be/src/vec/exprs/vmatch_predicate.cpp +++ b/be/src/vec/exprs/vmatch_predicate.cpp @@ -136,7 +136,7 @@ Status VMatchPredicate::evaluate_inverted_index(VExprContext* context, uint32_t Status VMatchPredicate::execute(VExprContext* context, Block* block, int* result_column_id) { DCHECK(_open_finished || _getting_const_col); - if (_can_fast_execute && fast_execute(context, block, result_column_id)) { + if (fast_execute(context, block, result_column_id)) { return Status::OK(); } DBUG_EXECUTE_IF("VMatchPredicate.execute", {