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

Refactor CTE-related code and reduce recompilations #3989

Merged
merged 2 commits into from Jan 29, 2024

Conversation

katzyn
Copy link
Contributor

@katzyn katzyn commented Jan 28, 2024

  1. CTEs are extracted from TableView into own class, their code is too different from each other.
  2. WITH and WITH RECURSIVE now have a different meaning. When RECURSIVE is specified, column names are mandatory (actually they were always required for recursive queries). When RECURSIVE is not specified, queries may not be recursive (and we can compile them faster without any quirks). WITH RECURSIVE clause cannot be used inside another WITH RECURSIVE clause. These requirements are described in the SQL Standard anyway.
  3. Unnecessary recompilations during parsing of CTEs are removed.

@manticore-projects
Copy link
Contributor

I just want to say a big Thank You for working on this.
Please do let me know if I can assist with anything, e.g. testing or documentation.

@katzyn
Copy link
Contributor Author

katzyn commented Jan 28, 2024

I can't correct grammar of WITH clause in documentation due to #3372, documentation of table references is also outdated.

@manticore-projects
Copy link
Contributor

I can't correct grammar of WITH clause in documentation due to #3372, documentation of table references is also outdated.

I will look into this next week and would tell you what I get working and what not.

@@ -2483,17 +2486,13 @@ private Query parseQueryExpression() {
QueryScope outerQueryScope = queryScope;
Query query;
if (readIf(WITH)) {
queryScope = new QueryScope(outerQueryScope);
boolean isPotentiallyRecursive = readIf("RECURSIVE");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why potentially? I'm ok with making it a requirement for this keyword to be correctly used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a definition from the SQL Standard. When RECURSIVE is specified, a with list and its elements are potentially recursive, when it isn't specified they are non-recursive.

Elements of a potentially recursive list aren't required to be recursive, but they have the same restrictions as recursive (such as mandatory column names).

@katzyn katzyn merged commit 2a29f47 into h2database:master Jan 29, 2024
2 checks passed
@katzyn katzyn deleted the cte branch January 29, 2024 13:09
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.

None yet

3 participants