diff --git a/be/src/exprs/expr.cpp b/be/src/exprs/expr.cpp index 89e3077e4bcfd3..b09bc6cfb198eb 100644 --- a/be/src/exprs/expr.cpp +++ b/be/src/exprs/expr.cpp @@ -524,9 +524,17 @@ Status Expr::prepare(const std::vector& ctxs, RuntimeState* state, Status Expr::prepare(RuntimeState* state, const RowDescriptor& row_desc, ExprContext* context) { DCHECK(_type.type != INVALID_TYPE); + ++context->_depth_num; + if (context->_depth_num > config::max_depth_of_expr_tree) { + return Status::InternalError( + fmt::format("The depth of the expression tree is too big, make it less than {}", + config::max_depth_of_expr_tree)); + } for (int i = 0; i < _children.size(); ++i) { RETURN_IF_ERROR(_children[i]->prepare(state, row_desc, context)); } + + --context->_depth_num; return Status::OK(); } diff --git a/be/src/exprs/expr_context.h b/be/src/exprs/expr_context.h index e61d60fd000056..6b94a1ab741716 100644 --- a/be/src/exprs/expr_context.h +++ b/be/src/exprs/expr_context.h @@ -186,6 +186,9 @@ class ExprContext { /// Calls the appropriate Get*Val() function on 'e' and stores the result in result_. /// This is used by Exprs to call GetValue() on a child expr, rather than root_. void* get_value(Expr* e, TupleRow* row, int precision = 0, int scale = 0); + + /// The depth of expression-tree. + int _depth_num = 0; }; inline void* ExprContext::get_value(TupleRow* row) {