diff --git a/src/graph/util/ExpressionUtils.cpp b/src/graph/util/ExpressionUtils.cpp index 415532cddd2..98d9b93325f 100644 --- a/src/graph/util/ExpressionUtils.cpp +++ b/src/graph/util/ExpressionUtils.cpp @@ -18,6 +18,8 @@ #include "graph/context/QueryExpressionContext.h" #include "graph/visitor/FoldConstantExprVisitor.h" +DEFINE_int32(max_expression_depth, 512, "Max depth of expression tree."); + namespace nebula { namespace graph { @@ -1221,7 +1223,7 @@ bool ExpressionUtils::checkExprDepth(const Expression *expr) { size -= 1; } depth += 1; - if (depth > ExpressionUtils::kMaxDepth) { + if (depth > FLAGS_max_expression_depth) { return false; } } diff --git a/src/graph/util/ExpressionUtils.h b/src/graph/util/ExpressionUtils.h index f42241f348b..c2efd3a7580 100644 --- a/src/graph/util/ExpressionUtils.h +++ b/src/graph/util/ExpressionUtils.h @@ -19,6 +19,8 @@ #include "graph/visitor/FindVisitor.h" #include "graph/visitor/RewriteVisitor.h" +DECLARE_int32(max_expression_depth); + namespace nebula { class ObjectPool; namespace graph { @@ -166,8 +168,6 @@ class ExpressionUtils { static bool isGeoIndexAcceleratedPredicate(const Expression* expr); static bool checkExprDepth(const Expression* expr); - - static constexpr int32_t kMaxDepth = 512; }; } // namespace graph diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 1cdf988d921..ce93d052bf1 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -560,7 +560,7 @@ expression if(!graph::ExpressionUtils::checkExprDepth($1)){ // delete $1; std::ostringstream errStr; - errStr << "The above expression's depth exceeds the maximum depth:" << graph::ExpressionUtils::kMaxDepth; + errStr << "The above expression's depth exceeds the maximum depth:" << FLAGS_max_expression_depth; throw nebula::GraphParser::syntax_error(@1, errStr.str()); } $$ = $1; diff --git a/tests/common/nebula_service.py b/tests/common/nebula_service.py index 1958ca15086..d20a7bda8dc 100644 --- a/tests/common/nebula_service.py +++ b/tests/common/nebula_service.py @@ -228,6 +228,8 @@ def _make_params(self, **kwargs): # Login retry self.graphd_param['failed_login_attempts'] = '5' self.graphd_param['password_lock_time_in_secs'] = '10' + # expression depth limit + self.graphd_param['max_expression_depth'] = '128' self.storaged_param = copy.copy(_params) self.storaged_param['local_config'] = 'false' diff --git a/tests/tck/features/expression/Depth.feature b/tests/tck/features/expression/Depth.feature index 71bf5e3498e..2351ad1e2eb 100644 --- a/tests/tck/features/expression/Depth.feature +++ b/tests/tck/features/expression/Depth.feature @@ -9,32 +9,16 @@ Feature: Check Expression Depth Scenario: yield exceeds expression When executing query: """ - YIELD 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + - 1 + 1 + 1 + 1 + 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