Skip to content

Parser: fix exponential parse time on speculative prefix parsing#2352

Open
LucaCappelletti94 wants to merge 1 commit into
apache:mainfrom
LucaCappelletti94:pathological6
Open

Parser: fix exponential parse time on speculative prefix parsing#2352
LucaCappelletti94 wants to merge 1 commit into
apache:mainfrom
LucaCappelletti94:pathological6

Conversation

@LucaCappelletti94
Copy link
Copy Markdown
Contributor

parse_prefix speculatively interprets the next token as a reserved-word expression head and, on failure, falls back to treating it as an unreserved identifier. Both arms can independently recurse into the same downstream position, so inputs like IF(current_time(current_time(...x were re-walked at every level for 2^N total work. Each parse_prefix failure is now memoized by start position so the second visit short-circuits.

Same family as #2344 and the speculative NOT prefix fix on pathological-combined. PostgreSQL, release build:

depth size before after
10 134 B 900ms 399us
15 199 B >60s 110us
20 264 B >60s 109us
25 329 B >60s 126us
30 394 B >60s 124us

Regression test in tests/sqlparser_common.rs runs the parse on a worker thread with a 5-second hang guard. Criterion bench under sqlparser_bench tracks perf at n=10/20/30.

@LucaCappelletti94
Copy link
Copy Markdown
Contributor Author

Me watching yet another fuzzer crash:

image

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