Repository navigation
Parser: fix quadratic parse time on REGEXP, MATCH, GLOB and DIV chains - #3033
Open
moshap-firebolt wants to merge 1 commit into
Open
moshap-firebolt wants to merge 1 commit into
moshap-firebolt wants to merge 1 commit into
Conversation
The SQLite hook for REGEXP, MATCH and GLOB and the MySQL and Spark hooks for DIV receive the left operand by reference and clone it, so a chain of n operators takes time quadratic in n, and a long one overflows the stack in the recursive clone. Parse them in parse_infix, which owns the operand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3033 +/- ##
==========================================
- Coverage 83.56% 83.54% -0.02%
==========================================
Files 42 42
Lines 35689 35650 -39
Branches 35689 35650 -39
==========================================
- Hits 29822 29783 -39
Misses 2429 2429
Partials 3438 3438 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
LucaCappelletti94
requested changes
Nov 25, 2026
LucaCappelletti94
left a comment
Contributor
There was a problem hiding this comment.
Please add the fuzzer seeds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
parse_infixhooks forREGEXP,MATCHandGLOBinSQLiteDialectand forDIVinMySqlDialectandSparkSqlDialectreceive the left operand as&Exprand clone it. In a left-deep chain each operator clones everything to its left, so the parse time is quadratic in the chain length, and a long chain overflows the stack in the recursive clone:Release build, main
6a37ecb3: 1,000 operators take 80 ms, 2,000 take 330 ms and 4,000 take 1.6 s. With this change 4,000 take 6 ms.Parser::parse_infixnow handles these keywords for those dialects. It owns the operand, so it moves it into theBinaryOp. The hooks and the sharedparse_div_infixhelper are removed. The AST is unchanged.Tests: a 5,000-operator chain for each of the four operators, which overflows the stack without the change, and
a REGEXP ANY(b)anda DIV ANY(b), whose right operand stays an ordinary expression.This PR was prepared with AI assistance (Claude).
Dialects: SQLite, MySQL, Spark
🤖 Generated with Claude Code