Skip to content

Parser: fix exponential parse time on named-arg chains#2349

Open
LucaCappelletti94 wants to merge 4 commits into
apache:mainfrom
LucaCappelletti94:pathological2
Open

Parser: fix exponential parse time on named-arg chains#2349
LucaCappelletti94 wants to merge 4 commits into
apache:mainfrom
LucaCappelletti94:pathological2

Conversation

@LucaCappelletti94
Copy link
Copy Markdown
Contributor

@LucaCappelletti94 LucaCappelletti94 commented May 22, 2026

parse_function_args wrapped parse_expr in maybe_parse for the <expr> <op> <expr> named-arg path on PostgreSQL/MSSQL, so rollback re-walked nested function calls and cost compounded to ~2^N. Same shape as #2344 at a different parser site.

Fix: parse the leading expression once with parse_wildcard_expr, then maybe_parse only the <op> <expr> tail.

Bench on PostgreSqlDialect:

n before after
5 78 us 15 us
10 2.4 ms 29 us
15 79 ms 42 us

Adds a timeout-based regression test and criterion bench mirroring #2344.

If anyone is curious as to how I am finding these, the TLDR is that I am fuzzing libraries downhill which use sqlparser, and keep getting timeouts because of these exponential cases. Unfortunately, there are still several to be deal with, but there is only so much time in a day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant