-
Notifications
You must be signed in to change notification settings - Fork 606
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
Enable subqueries inside views #10517
Conversation
⚪ Test history | Ya make output | Test bloat
⚪ Test history | Ya make output | Test bloat | Test bloat
🟢
*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation |
⚪ Test history | Ya make output | Test bloat
🟢
*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation |
Ticket
Please see the ticket for the problem description.
Context
Views store only the text of the query that was used to create them. Nevertheless, we build the AST node of the view's select statement to validate it during the parsing of the
CREATE VIEW
statement.Our goal is to validate view queries as strictly as possible. This means we validate the view query using a parser context that closely resembles the one that would be created when the view is queried.
Let's name the three parser contexts that are relevant for views:
CREATE VIEW
statement is executed.SELECT
statement from a view.Using the creation context for validation would allow queries with references to named expressions defined in the creation context to pass validation, which we want to avoid. Unfortunately, implementing this restriction introduces some issues.
Cause
The view validation context lacks blocks to store subquery references. Unlike the TSqlQuery translator, we cannot simply create new blocks because the query references we create must be passed back to the parent context for further translation.
The only viable solution I see is to use the blocks from the current parent context within the validation context. This approach has been implemented in this pull request.
Note
The main commit is:
The others are supplementary.