Skip to content

Commit f0d0a24

Browse files
PostgreSQL: regression test for compound-chain blowup
1 parent 04a048f commit f0d0a24

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/sqlparser_postgres.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)