Skip to content

Parser: Fix exponential parse time on nested qualified keyword calls - #3006

Open
SAMARTHJAISWAL wants to merge 2 commits into
apache:mainfrom
SAMARTHJAISWAL:parser/qualified-call-blowup
Open

SAMARTHJAISWAL wants to merge 2 commits into
apache:mainfrom
SAMARTHJAISWAL:parser/qualified-call-blowup

Conversation

@SAMARTHJAISWAL

Copy link
Copy Markdown

Fixes #3001.

Nested schema-qualified calls to a keyword function doubled the parse time per level:

SELECT a.CEIL(a.CEIL(a.CEIL(x)))   -- 22 levels: ~7 s

After a ., a word followed by ( was first parsed speculatively with parse_prefix. For CEIL, FLOOR, SUBSTRING or TRIM that returns the keyword's own expression, which the validator rejects, and the None branch then parsed the same arguments again as a function call.

A word after . now skips the speculative parse, as a word not followed by ( already did, and the None branch reads it as an identifier or a function call. That branch now checks for the outer join operator, so t.c (+) is still an identifier.

Not fixed here: #3002 (DuckDB u.u(k=u.u(k=...) still doubles after this change, so it has another cause.

Tests: a hang guard for the four keyword calls nested 30 deep, and a fuzz seed. cargo test --all-features and cargo fmt pass.

AI assistance: I used an AI assistant to find the cause and to write the change and the test. I have read and understood all of it and ran the tests myself.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exponential parse time on nested qualified CEIL, FLOOR, SUBSTRING or TRIM calls (regression from #2685)

1 participant