fix: detect non-recursive CTEs in the recursive WITH clause#9836
Merged
alamb merged 5 commits intoapache:mainfrom Apr 1, 2024
Merged
fix: detect non-recursive CTEs in the recursive WITH clause#9836alamb merged 5 commits intoapache:mainfrom
WITH clause#9836alamb merged 5 commits intoapache:mainfrom
Conversation
jonahgao
commented
Mar 28, 2024
| let recursive_plan = | ||
| self.set_expr_to_plan(*right_expr, &mut planner_context.clone())?; | ||
|
|
||
| // Check if the recursive term references the CTE itself, |
Member
Author
There was a problem hiding this comment.
Here are the main changes.
jonahgao
commented
Mar 28, 2024
| } | ||
| } | ||
|
|
||
| pub(super) fn set_operation_to_plan( |
Member
Author
There was a problem hiding this comment.
This function is reused by CTE.
jonahgao
commented
Mar 28, 2024
| } | ||
|
|
||
| #[test] | ||
| fn cte_use_same_name_multiple_times() { |
Member
Author
There was a problem hiding this comment.
This test is moved to slt.
alamb
approved these changes
Mar 30, 2024
Contributor
alamb
left a comment
There was a problem hiding this comment.
Thank you @jonahgao -- this PR looks really nice 🏆 -- I especially like how you have refactored the code into smaller and easier to understand functions
I apologize for the delay in reviewing. 🚀
cc @matthewgapp
Member
Author
|
No worries about the delay :) And thank you for the review @alamb ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #9804.
Rationale for this change
If the recursive term of a CTE does not reference the CTE itself, then it should be compiled to a non-recursive CTE, otherwise it may lead to incorrect query results.
This PR traverses the
LogicalPlanof the recursive term, looking for a table scan of the work table to determine if there is a self-reference.What changes are included in this PR?
cte.WITHclause.Are these changes tested?
Yes
Are there any user-facing changes?
No