moshap-firebolt opened a new pull request, #3033: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/3033
The `parse_infix` hooks for `REGEXP`, `MATCH` and `GLOB` in `SQLiteDialect` and for `DIV` in `MySqlDialect` and `SparkSqlDialect` receive the left operand as `&Expr` and 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: ```sql SELECT a REGEXP b REGEXP b REGEXP b ... SELECT a DIV b DIV b DIV b ... ``` 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_infix` now handles these keywords for those dialects. It owns the operand, so it moves it into the `BinaryOp`. The hooks and the shared `parse_div_infix` helper 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)` and `a 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](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
