[improve](function) get result from constant_col when expr is const (#29403)
This commit is contained in:
@ -95,6 +95,9 @@ void VCaseExpr::close(VExprContext* context, FunctionContext::FunctionStateScope
|
||||
}
|
||||
|
||||
Status VCaseExpr::execute(VExprContext* context, Block* block, int* result_column_id) {
|
||||
if (is_const_and_have_executed()) { // const have execute in open function
|
||||
return get_result_from_const(block, _expr_name, result_column_id);
|
||||
}
|
||||
ColumnNumbers arguments(_children.size());
|
||||
for (int i = 0; i < _children.size(); i++) {
|
||||
int column_id = -1;
|
||||
|
||||
@ -138,6 +138,10 @@ void VectorizedFnCall::close(VExprContext* context, FunctionContext::FunctionSta
|
||||
|
||||
Status VectorizedFnCall::execute(VExprContext* context, vectorized::Block* block,
|
||||
int* result_column_id) {
|
||||
if (is_const_and_have_executed()) { // const have execute in open function
|
||||
return get_result_from_const(block, _expr_name, result_column_id);
|
||||
}
|
||||
|
||||
// TODO: not execute const expr again, but use the const column in function context
|
||||
vectorized::ColumnNumbers arguments(_children.size());
|
||||
for (int i = 0; i < _children.size(); ++i) {
|
||||
|
||||
@ -554,4 +554,12 @@ Status VExpr::check_constant(const Block& block, ColumnNumbers arguments) const
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status VExpr::get_result_from_const(vectorized::Block* block, const std::string& expr_name,
|
||||
int* result_column_id) {
|
||||
*result_column_id = block->columns();
|
||||
auto column = ColumnConst::create(_constant_col->column_ptr, block->rows());
|
||||
block->insert({std::move(column), _data_type, expr_name});
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
} // namespace doris::vectorized
|
||||
|
||||
@ -220,6 +220,11 @@ protected:
|
||||
return res;
|
||||
}
|
||||
|
||||
bool is_const_and_have_executed() { return (is_constant() && (_constant_col != nullptr)); }
|
||||
|
||||
Status get_result_from_const(vectorized::Block* block, const std::string& expr_name,
|
||||
int* result_column_id);
|
||||
|
||||
Status check_constant(const Block& block, ColumnNumbers arguments) const;
|
||||
|
||||
/// Helper function that calls ctx->register(), sets fn_context_index_, and returns the
|
||||
|
||||
@ -94,6 +94,9 @@ void VInPredicate::close(VExprContext* context, FunctionContext::FunctionStateSc
|
||||
}
|
||||
|
||||
Status VInPredicate::execute(VExprContext* context, Block* block, int* result_column_id) {
|
||||
if (is_const_and_have_executed()) { // const have execute in open function
|
||||
return get_result_from_const(block, _expr_name, result_column_id);
|
||||
}
|
||||
// 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) {
|
||||
|
||||
Reference in New Issue
Block a user