File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9243,3 +9243,27 @@ fn parse_lock_table() {
92439243 }
92449244 }
92459245}
9246+
9247+ /// `parse_compound_expr` used to do 2^N work on `IF a.b.c...x.#` because every
9248+ /// `.` re-entered `parse_subexpr` over the rest of the chain.
9249+ #[ test]
9250+ fn parse_compound_chain_no_exponential_blowup ( ) {
9251+ use std:: sync:: mpsc;
9252+ use std:: thread;
9253+ use std:: time:: Duration ;
9254+
9255+ let chain: String = ( 0 ..30 )
9256+ . map ( |i| format ! ( "a{i}" ) )
9257+ . collect :: < Vec < _ > > ( )
9258+ . join ( "." ) ;
9259+ let sql = format ! ( "IF {chain}.#" ) ;
9260+
9261+ let ( tx, rx) = mpsc:: channel ( ) ;
9262+ thread:: spawn ( move || {
9263+ let _ = sqlparser:: parser:: Parser :: parse_sql ( & PostgreSqlDialect { } , & sql) ;
9264+ let _ = tx. send ( ( ) ) ;
9265+ } ) ;
9266+
9267+ rx. recv_timeout ( Duration :: from_secs ( 5 ) )
9268+ . expect ( "parser should reject this quickly, not loop exponentially" ) ;
9269+ }
You can’t perform that action at this time.
0 commit comments