-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add #[recursive]
#1522
base: main
Are you sure you want to change the base?
Add #[recursive]
#1522
Conversation
458f748
to
a4a5794
Compare
a4a5794
to
73891ee
Compare
I was wondering if we should remove RecursionCounter with this PR. In my opinion, we shouldn't, because the ability to limit max recursion might be useful for some users still |
It seems this PR doesn't have any significant performance impact.
|
FYI, I marked this ready for review. @peter-toth @Eason0729, if you guys want to take a look 🌻 |
@blaginin thanks for looking to fix this! Currently the preference is to avoid a third-party dependency for this issue, ideally fixing up the parser behavior instead to properly handle deeply nested input. See comment here for a bit more context on rationale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @blaginin. LGTM except for some number in unit test.
I left some comments, and any number above 40000 seems to overflow stack without #[recursive]
.
@@ -42,6 +42,46 @@ fn basic_queries(c: &mut Criterion) { | |||
group.bench_function("sqlparser::with_select", |b| { | |||
b.iter(|| Parser::parse_sql(&dialect, with_query)); | |||
}); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For large_statement
, making separated test would make differentiating potential(future) regression easier.
It's a suggestion(fine to leave it as it is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understood your comment, sorry. I added tests for parsing large statements in tests/sqlparser_common.rs. Do you think we should test something else?
#[test] | ||
fn overflow() { | ||
let expr = std::iter::repeat("1") | ||
.take(1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1000 is reasonable for general usage, but 1000 won't overflow without recursive macro. Maybe we could increase it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it depends on the platform. IMO, the most important thing is that it overflows the stack in the CI
|
||
#[test] | ||
fn overflow() { | ||
let cond = (0..1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reason as sqlparser_common::overflow
test. Maybe we could increase it(increase the number 1000
).
@iffyio, we had done some research on stacker / recursive in apache/datafusion#13310 to verify concerns before we added it to datafusion: apache/datafusion#13310 (review) / apache/datafusion#13177 (comment) |
Sorry for missing that context when reviewing. So we would like to avoid using recursive for stablility, maybe try...
|
Thanks for the review!! 🙂
We ended up using |
Closes #984, related to apache/datafusion#9375 (comment)
Todo: