Skip to content
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

Merged
merged 3 commits into from
Oct 18, 2024
Merged

Conversation

jepett0
Copy link
Collaborator

@jepett0 jepett0 commented Oct 16, 2024

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:

  1. Creation Parser Context. The context in which the CREATE VIEW statement is executed.
  2. Validation Parser Context. Used for view query validation.
  3. Execution Parser Context. Used during the execution of a 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.

Copy link

github-actions bot commented Oct 16, 2024

2024-10-16 13:31:44 UTC Pre-commit check linux-x86_64-relwithdebinfo for 1492f71 has started.
2024-10-16 13:31:56 UTC Artifacts will be uploaded here
2024-10-16 13:35:04 UTC ya make is running...
🟡 2024-10-16 14:35:29 UTC Some tests failed, follow the links below. Going to retry failed tests...

Test history | Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
76072 62099 0 1 13870 102

2024-10-16 14:43:31 UTC ya make is running... (failed tests rerun, try 2)
🟢 2024-10-16 14:55:17 UTC Tests successful.

Test history | Ya make output | Test bloat | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
102 (only retried tests) 4 0 0 0 98

🟢 2024-10-16 14:55:24 UTC Build successful.
🟢 2024-10-16 14:55:43 UTC ydbd size 2.8 GiB changed* by +29.0 KiB, which is < 100.0 KiB vs main: OK

ydbd size dash main: 362f6f5 merge: 1492f71 diff diff %
ydbd size 3 027 720 680 Bytes 3 027 750 328 Bytes +29.0 KiB +0.001%
ydbd stripped size 480 017 112 Bytes 480 017 880 Bytes +768 Bytes +0.000%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

Copy link

github-actions bot commented Oct 16, 2024

2024-10-16 13:33:41 UTC Pre-commit check linux-x86_64-release-asan for 1492f71 has started.
2024-10-16 13:33:45 UTC Artifacts will be uploaded here
2024-10-16 13:36:42 UTC ya make is running...
🟡 2024-10-16 14:58:00 UTC Some tests failed, follow the links below. This fail is not in blocking policy yet

Test history | Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
13185 12937 0 56 90 102

🟢 2024-10-16 14:59:06 UTC Build successful.
🟢 2024-10-16 14:59:42 UTC ydbd size 5.7 GiB changed* by +62.7 KiB, which is < 100.0 KiB vs main: OK

ydbd size dash main: 362f6f5 merge: 1492f71 diff diff %
ydbd size 6 128 233 176 Bytes 6 128 297 400 Bytes +62.7 KiB +0.001%
ydbd stripped size 1 529 059 856 Bytes 1 529 061 456 Bytes +1.6 KiB +0.000%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

@jepett0 jepett0 marked this pull request as ready for review October 16, 2024 15:19
@jepett0 jepett0 requested a review from a team as a code owner October 16, 2024 15:19
@jepett0 jepett0 merged commit 56b80f8 into ydb-platform:main Oct 18, 2024
16 checks passed
jepett0 added a commit to jepett0/ydb that referenced this pull request Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants