-
Notifications
You must be signed in to change notification settings - Fork 495
adapter: Inherit allow_subqueries from outer context in sql_impl #34892
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
base: main
Are you sure you want to change the base?
Conversation
|
The CI fail is caused by the PR; I'm investigating. Edit: Fixed in the second commit. |
e9c7987 to
6a790c3
Compare
def-
left a comment
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.
Definitely fixes the bug, thanks for adding a test
|
Any chance to merge this? Currently blocking introducing SQLancer++ testing |
| # TODO: Bad error msg, because we handle ExprContext names badly when inner contexts are created by `with_name`. See | ||
| # https://github.com/MaterializeInc/database-issues/issues/10074 | ||
| statement error db error: ERROR: static function definition \(or its outer context 'mz_internal\.mz_role_oid'\) does not allow subqueries | ||
| UPDATE t0 SET c1=HAS_SECRET_PRIVILEGE(t0.c1, '30 minutes') WHERE (t0.c1 BETWEEN t0.c1 AND t0.c1); |
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 would be good to have a basic test that shows that the subquery is still allowed (e.g., outside the context of a set).
SELECT HAS_SECRET_PRIVILEGE(t0.c1, '30 minutes') FROM t0 LIMIT 0;
Additionally, maybe it would be good to have some examples of deeper nesting?
mtabebe
left a comment
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.
My reading of this makes sense, just some small test suggestions
Fixes https://github.com/MaterializeInc/database-issues/issues/10067. (And unblocks #34881)
The problem was that we were simply always statically allowing subqueries in the
ExprContextinsql_impl. This meant that we allowed subqueries there even if an outer context (such as theSETpart of anUPDATE) didn't allow it. This PR fixes this by passing in the outer context, and inheriting whether that allows subqueries.(Unfortunately, the error msg didn't come out nice, see the issue that is linked from the slt.)
Edit: The second commit tweaks how we handle errors in
generate_column_casts. The issue was that that function relied on the buggy behavior ofsql_implthat allowed subqueries without regard to the outer context, so that it can catch subqueries specifically bylower_uncorrelated. So, I've now had to explicitly make the outer context allow subqueries, so thatlower_uncorrelatedcan keep catching it.