Add configurable expression depth limit during AST building#5602
Conversation
PR Reviewer Guide 🔍(Review updated until commit 7d16ae4)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 7d16ae4 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 82fa28e
Suggestions up to commit 31772f2
|
31772f2 to
a7c0fe2
Compare
|
Persistent review updated to latest commit a7c0fe2 |
a7c0fe2 to
82fa28e
Compare
|
Persistent review updated to latest commit 82fa28e |
Introduce plugins.query.max_expression_depth (default 1000; 0 to disable) to bound expression nesting depth during AST building, improving robustness for very large or deeply nested SQL/PPL queries. Signed-off-by: Chen Dai <daichen@amazon.com>
82fa28e to
7d16ae4
Compare

Description
Adds a configurable safeguard on expression nesting depth during SQL/PPL parsing to improve robustness for very large or deeply nested queries. Introduces the dynamic setting
plugins.query.max_expression_depth(default 1000; 0 to disable). Tested SQL/PPL both Lucene and composite index with default-Xss 1mas well as all ClickBench queries.Examples
With
plugins.query.max_expression_depth(default1000), a query whose expression nesting exceeds the limit is rejected with400 Bad Requestinstead of triggering aStackOverflowError/ node crash.References
Bounding query/expression nesting to prevent parser or planner stack overflow is a well-established practice. Comparable safeguards in other engines:
SQLITE_MAX_EXPR_DEPTH(runtimeSQLITE_LIMIT_EXPR_DEPTH)sqlite3ExprCheckHeight())max_stack_depthcheck_stack_depth())thread_stack(+ internalcheck_stack_overrun());max_sp_recursion_depthindex.query.max_nested_depthboolqueries (query-structure depth)indices.query.bool.max_clause_countRexUtil.toCnf(maxCnfNodeCount, …)→PlanTooComplexErrorRelated Issues
Part of #5246
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.