Parser: fix exponential parse time on table-factor paren chains#2372
Open
moshap-firebolt wants to merge 1 commit into
Open
Parser: fix exponential parse time on table-factor paren chains#2372moshap-firebolt wants to merge 1 commit into
moshap-firebolt wants to merge 1 commit into
Conversation
7f8080c to
39a0f04
Compare
`parse_table_factor` speculatively parses `(...)` as a derived table; on failure it rewinds and falls through to `parse_table_and_joins`, which recurses back into `parse_table_factor` and re-attempts the same speculative parse at every deeper paren. Both arms walk the remaining chain, so on inputs like `SELECT 1 FROM ((((...` work doubles per level. Caching the position at which the speculative arm failed short-circuits the second descent. Measured on `GenericDialect` with `with_recursion_limit(256)`, release build: | N | Before | After | |----|---------|--------| | 10 | 20 ms | 57 us | | 20 | 820 ms | 119 us | | 25 | 2.8 s | 281 us | | 30 | 7.9 s | 345 us |
39a0f04 to
6d5b911
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
parse_table_factorspeculatively parses(...)as a derived table; onfailure it rewinds and falls through to
parse_table_and_joins, whichrecurses back into
parse_table_factorand re-attempts the samespeculative parse at every deeper paren. Both arms walk the remaining
chain, so on inputs like
SELECT 1 FROM ((((...work doubles per level.Caching the position at which the speculative arm failed short-circuits
the second descent.
Measured on
GenericDialectwithwith_recursion_limit(256), releasebuild: