You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MySQL: exponential parse time on chains of BINARY operands that fail to parse (regression from #2146) #3000
A chain of BINARY operands that ends in a syntax error doubles the parse time per operand in the MySQL dialect. Before #2146 added the BINARY cast (0.60.0) the same input failed in microseconds:
SELECT BINARY-BINARY-BINARY-BINARY--FIELDS IN -- n operands
bytes main 0.60.0
n=16 136 129 ms 0.016 ms
n=18 150 0.5 s 0.013 ms
n=20 164 2.1 s 0.013 ms
Any failure after the chain does it (SELECT BINARY+BINARY+...+ too). With a valid ending (...-BINARY-1), or in GenericDialect, it is linear.
use sqlparser::{dialect::MySqlDialect, parser::Parser};
let sql = format!("SELECT BINARY{}--FIELDS IN", "-BINARY".repeat(20));
let _ = Parser::parse_sql(&MySqlDialect {}, &sql); // error after ~2 s
Tested on main 9429cd3 and crates.io 0.64.0, 0.63.0 and 0.61.0 (the first release with #2146); 0.60.0 is linear.
Found with a coverage-guided performance fuzzer; I used AI assistance for triage and verified every case above.
The same speculation (the typed-string maybe_parse at the top of parse_prefix_inner) also blows up in Snowflake, on nested IDENTIFIER(...). Here the input parses. This is a regression from #1929; before it (0.57.0) the input parsed in microseconds:
SELECT IDENTIFIER(IDENTIFIER(IDENTIFIER('t'))) -- nested n levels
bytes main 0.57.0
n=16 202 75 ms 0.018 ms
n=20 250 1.2 s 0.021 ms
n=22 274 4.8 s 0.020 ms
Same in SELECT * FROM IDENTIFIER(...) and CREATE TABLE IDENTIFIER(...). The same input in GenericDialect is linear.
use sqlparser::{dialect::SnowflakeDialect, parser::Parser};
let sql = format!("SELECT {}'t'{}", "IDENTIFIER(".repeat(22), ")".repeat(22));
Parser::parse_sql(&SnowflakeDialect {}, &sql).unwrap(); // ~5 s
Tested on main 9429cd3 and crates.io 0.64.0, 0.63.0 and 0.58.0 (the first release with #1929); 0.57.0 is linear.
Activity
alpaylan commentedon Nov 18, 2026
The same speculation (the typed-string
maybe_parseat the top ofparse_prefix_inner) also blows up in Snowflake, on nestedIDENTIFIER(...). Here the input parses. This is a regression from #1929; before it (0.57.0) the input parsed in microseconds:Same in
SELECT * FROM IDENTIFIER(...)andCREATE TABLE IDENTIFIER(...). The same input in GenericDialect is linear.Tested on main 9429cd3 and crates.io 0.64.0, 0.63.0 and 0.58.0 (the first release with #1929); 0.57.0 is linear.