Skip to content

fix(query_engine): limit the nesting of queries - #1828

Merged
taepper merged 2 commits into
mainfrom
1812-deeply-nested-fix
Nov 18, 2026
Merged

taepper merged 2 commits into
mainfrom
1812-deeply-nested-fix

Conversation

@taepper

@taepper taepper commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

resolves #1812

Summary

This adds a recursion-guard to the parser of queries which is at the start of every recursive function. This recursion-guard is used to limit the maximum depth of queries to 100 levels. (postfix expressions like x.f().f().f() also count as one nesting as per Uniform-Function-Call-Syntax)

PR Checklist

  • All necessary documentation has been adapted or there is an issue to do so.
  • The implemented feature is covered by an appropriate test.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This is a preview of the changelog of the next release. If this branch is not up-to-date with the current main branch, the changelog may not be accurate. Rebase your branch on the main branch to get the most accurate changelog.

Note that this might contain changes that are on main, but not yet released.

Changelog:

0.17.6 (2026-11-18)

Features

  • query_engine: add type casts at query execution time (#1799) (f7acdf0)

Bug Fixes

  • query_engine: do not decompress every row before applying a limit (#1833) (d3c06a2)
  • query_engine: evaluate out-of-bound .at() expressions to null for null inputs (#1839) (511d2ee)
  • query_engine: limit the nesting of queries (aad9998)

@fengelniederhammer
fengelniederhammer requested a balanced review from Copilot November 17, 2026 07:54
@taepper
taepper force-pushed the 1812-deeply-nested-fix branch 2 times, most recently from 64fa0bb to ce790b4 Compare November 17, 2026 07:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The parser can still create over-depth ASTs through parenthesized postfix chains, and a regression test retains a dangling string_view that can trigger use-after-free under ASAN.

2 open issues
What changed in this PR

This PR addresses #1812 by adding nesting guards to the SaneQL parser to reject deeply nested queries before they stall or exhaust the query engine’s stack.

Changes:

  • Introduces a 100-level parser nesting limit, including postfix chains.
  • Adds parser boundary tests, deep-input tests, endpoint checks, and user documentation.
  • Avoids expensive filter string formatting when trace logging is disabled.
File Description
src/​rhydb/​query_engine/​scalar_expressions/​int_between.cpp Guards trace-only string formatting.
src/​rhydb/​query_engine/​scalar_expressions/​and.cpp Skips diagnostic string construction when trace logging is disabled.
src/​rhydb/​query_engine/​saneql/​parser.test.cpp Tests nesting boundaries, excessive depth, and flat logical chains.
src/​rhydb/​query_engine/​saneql/​parser.h Declares the nesting limit, recursion guard, and postfix helper.
src/​rhydb/​query_engine/​saneql/​parser.cpp Implements nesting checks and recursive postfix parsing.
endToEndTests/​test/​query.test.js Checks rejection of deeply nested queries and subsequent server health.
documentation/​query_documentation.md Documents the nesting limit and counting rules.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The unary-expression depth guard double-counts the current !, rejecting 99 negations despite their allowed tree depth of 100; its scope needs correction and boundary tests.

1 open issue
2 resolved since last review

Review effort: Balanced

@taepper
taepper force-pushed the 1812-deeply-nested-fix branch 2 times, most recently from 2134cf6 to 780ba07 Compare November 17, 2026 13:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unary negation double-counts the active parser guard and AST depth, rejecting valid expressions at the documented 100-level boundary.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread documentation/query_documentation.md Resolved

@fengelniederhammer fengelniederhammer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@taepper
taepper merged commit 599d3a4 into main Nov 18, 2026
8 of 9 checks passed
@taepper
taepper deleted the 1812-deeply-nested-fix branch November 18, 2026 07:55
taepper pushed a commit that referenced this pull request Nov 18, 2026
🤖 I have created a release *beep* *boop*
---


## [0.17.6](v0.17.5...v0.17.6)
(2026-11-18)


### Features

* **query_engine:** add type casts at query execution time
([#1799](#1799))
([f7acdf0](f7acdf0))


### Bug Fixes

* **query_engine:** do not decompress every row before applying a limit
([#1833](#1833))
([d3c06a2](d3c06a2))
* **query_engine:** evaluate out-of-bound `.at()` expressions to null
for null inputs ([#1839](#1839))
([511d2ee](511d2ee))
* **query_engine:** limit the nesting of queries
([#1828](#1828))
([599d3a4](599d3a4))
* **query_engine:** treat Unicode whitespace as whitespace and report
non-ASCII errors ([#1816](#1816))
([edc1c02](edc1c02))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deeply nested queries will stall the query engine

3 participants