-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: detect non-recursive CTEs in the recursive WITH
clause
#9836
Conversation
let recursive_plan = | ||
self.set_expr_to_plan(*right_expr, &mut planner_context.clone())?; | ||
|
||
// Check if the recursive term references the CTE itself, |
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.
Here are the main changes.
} | ||
} | ||
|
||
pub(super) fn set_operation_to_plan( |
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.
This function is reused by CTE.
@@ -2992,16 +2992,6 @@ fn join_with_aliases() { | |||
quick_test(sql, expected); | |||
} | |||
|
|||
#[test] | |||
fn cte_use_same_name_multiple_times() { |
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.
This test is moved to slt.
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.
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
No worries about the delay :) And thank you for the review @alamb ! |
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
LogicalPlan
of 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
.WITH
clause.Are these changes tested?
Yes
Are there any user-facing changes?
No