Skip to content

Conversation

@JackieTien97
Copy link
Contributor

Description

Fixes an OOM issue caused by infinite recursion in ErrorHandler.isReachable when parsing certain invalid SQL queries (e.g., offset X limitY with syntax errors). The isReachable method was traversing the ANTLR ATN without tracking visited states, leading to infinite loops in the presence of epsilon transition cycles.

Changes

  • Modified ErrorHandler.java: Added a visited set to the isReachable BFS traversal to prevent processing the same state multiple times.
  • Added SqlParserErrorHandlerTest.java: A new unit test that reproduces the issue and verifies that the parser now correctly throws a ParsingException instead of hanging.

Verification

  • Added unit test SqlParserErrorHandlerTest passes.
  • Verified manually that select * from t1 offset 40 limit1 no longer causes OOM.

- Fix infinite recursion in  by tracking visited states during ATN traversal.
- Add  to verify the fix and prevent regression.
- This resolves the OOM issue caused by invalid SQL queries like .
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an Out-of-Memory (OOM) issue in the SQL parser's error handling caused by infinite recursion when traversing ANTLR's ATN (Augmented Transition Network) for error reporting. The bug occurred when parsing certain malformed SQL queries with syntax errors in LIMIT/OFFSET clauses.

Changes:

  • Added visited state tracking in ErrorHandler.isReachable() to prevent infinite loops in epsilon transition cycles
  • Added unit test to verify the parser correctly throws ParsingException instead of hanging
  • Updated .gitignore to exclude ANTLR-generated files

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/ErrorHandler.java Fixed infinite loop in isReachable BFS traversal by adding visited set to track processed states; reformatted long comments
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/SqlParserErrorHandlerTest.java Added unit test to verify parser throws exception instead of hanging on malformed LIMIT/OFFSET syntax
.gitignore Added entry to ignore ANTLR-generated files in relational-grammar module

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.35%. Comparing base (337ac47) to head (1118527).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #17023      +/-   ##
============================================
+ Coverage     39.22%   39.35%   +0.12%     
  Complexity      212      212              
============================================
  Files          5075     5075              
  Lines        340393   340397       +4     
  Branches      43443    43444       +1     
============================================
+ Hits         133536   133974     +438     
+ Misses       206857   206423     -434     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

JackieTien97 and others added 2 commits January 14, 2026 14:07
…ine/plan/relational/sql/ast/SqlParserErrorHandlerTest.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ine/plan/relational/sql/ast/SqlParserErrorHandlerTest.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud
Copy link

@JackieTien97 JackieTien97 merged commit fe0d0f3 into master Jan 14, 2026
30 of 31 checks passed
@JackieTien97 JackieTien97 deleted the ty/limitFix branch January 14, 2026 07:31
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.

1 participant