-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: recursive cte hangs on joins #9687
Conversation
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 (as always)
I agree the core problem is that the CrossJoinExec has shared state that is passed out to different calls to execute_stream
and in general ExecutionPlans
don't expect to have execute()
called with the same partition number multiple times.
I think some potential downside of the approach in this PR are:
- It doesn't work for User defined ExecutionPlan nodes (without a change that they won't discover until someone tries to run a recursive CTE)
- It won't work for any new ExecutionPlan nodes introduced we add to DataFusion unless someone thinks to test them with recursive CTEs
Thus, what do you think about the idea of basically creating an entirely new ExecutionPlan
via ExecutionPlan::with_new_children
?
That would definitely be less efficient but it would be more general and ensure all state was cleared
I've tried using Thank you for your advice @alamb , I agree that using Update: Switch to using |
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
Which issue does this PR close?
Closes #9680.
Rationale for this change
CrossJoin uses
OnceAsync
to load the left table into memory and caches it into the plan for the duration of the entire query.https://github.com/apache/arrow-datafusion/blob/b0b329ba39403b9e87156d6f9b8c5464dc6d2480/datafusion/physical-plan/src/joins/cross_join.rs#L61-L62
However, if the left table's data is derived from a CTE work table, the cached data may become outdated after each recursive iteration, because the work table may be changed. If we execute this plan again, there will be problems.
Therefore, those states in the plan, like cached data, need to be cleared whenever a new iteration begins.
What changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?
No