Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions be/src/vec/exprs/vin_predicate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,24 @@ 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();
}

size_t VInPredicate::skip_constant_args_size() const {
if (_is_args_all_constant && !_can_fast_execute) {
// 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
return 1;
}
return _children.size();
}

void VInPredicate::close(VExprContext* context, FunctionContext::FunctionStateScope scope) {
VExpr::close_function_context(context, scope, _function);
VExpr::close(context, scope);
Expand All @@ -115,9 +129,8 @@ Status VInPredicate::execute(VExprContext* context, Block* block, int* result_co
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) {
doris::vectorized::ColumnNumbers arguments(skip_constant_args_size());
for (int i = 0; i < skip_constant_args_size(); ++i) {
int column_id = -1;
RETURN_IF_ERROR(_children[i]->execute(context, block, &column_id));
arguments[i] = column_id;
Expand Down
3 changes: 3 additions & 0 deletions be/src/vec/exprs/vin_predicate.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class VInPredicate final : public VExpr {

std::string debug_string() const override;

size_t skip_constant_args_size() const;

const FunctionBasePtr function() { return _function; }

bool is_not_in() const { return _is_not_in; };
Expand All @@ -62,5 +64,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