-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Qualify macros only when called, and throw error on recursive macros #8224
Conversation
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 for the PR! Looks good - one more comment:
case ExpressionClass::SUBQUERY: { | ||
// replacing parameters within a subquery is slightly different | ||
auto &sq = (expr->Cast<SubqueryExpression>()).subquery; | ||
ParsedExpressionIterator::EnumerateQueryNodeChildren(*sq->node, [&](unique_ptr<ParsedExpression> &child) { |
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 that this will not work with TABLE
macros, correct? i.e. this will still fail:
create macro m1(a) as a+1;
create macro m2(a) as table select m1(a);
create or replace macro m1(a) as (from m2(42));
select m1(42);
I think it might make sense to have an expression recursion limit in the binder similar to what we have in the transformer (look for StackCheck
). Macros can also be used to circumvent the expression depth limit otherwise which can lead to a stack overflow.
I've implemented Also, I found a bug unrelated (I think) to this PR:
|
I think Python has a 10,000 level default on the stack and it can be edited with a parameter, in case that is helpful! |
Could you open an issue with that bug? |
Done #8287 I've also investigated why I could only set the limit to 128, and it's because there's a lot of recursive calls in the Binder, especially when binding table macro's. This is one recursive binding iteration:
In this cycle, the stack counter of |
I wonder if there is any place where a large amount of data is placed onto the stack (e.g. a large array)? 128 does seem very low for a limit. As Alex mentioned Python defaults to 10K, SQLite defaults to 1K. We might also want to add more recursion checking in e.g. |
I don't think any large stack allocations are being done. For every pass through the main switch in I've tried again and increased the limit to 425 (that's as far as I went with my binary search). Considering we have 16 function calls per increment, that's a stack depth 425 * 16 = 6800. If we want, we could consider increasing the stack size at compile-time. I could also add a special case to |
I think perhaps we need to add more instances of the StackChecker along the path then. Shouldn't the stack depth be incremented multiple times as We should likely also add a stack increment to |
Thanks! |
Fixes #8141