-
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
Convert LogicalPlanBuilder to use Arc<LogicalPlan> #12040
Conversation
Summary Update struct to use Arc. Verified test passes. Used Arc::clone as much as I can; and unwrap_arc when a owned LogicalPlan is required. Keep pub fn input unchanged as LogicalPlan to limit change scope. If we change the pub fn, we can also get rid of this pattern: ``` unnest(unwrap_arc(self.plan), ...).map(Self::from) ```
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 @jc4x4 🙏 This looks like a good idea to me
I started the CI tests for this PR and left a few comments
@@ -145,7 +150,7 @@ impl LogicalPlanBuilder { | |||
coerce_plan_expr_for_schema(&recursive_term, self.plan.schema())?; | |||
Ok(Self::from(LogicalPlan::RecursiveQuery(RecursiveQuery { | |||
name, | |||
static_term: Arc::new(self.plan.clone()), | |||
static_term: Arc::clone(&self.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 seems the only place a deep clone is "saved"?
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.
Another example in line 470.
project((*input).clone(), expr)
project(unwrap_arc(input), expr)
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.
Ah yes, here it might avoid the clone as well 👍
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.
FWIW I think we can avoid the clone by changing the signature from
pub fn to_recursive_query(
&self,
to
pub fn to_recursive_query(
self,
(the builder should be consumed)
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.
Another example in line 470.
I think since this is an associated function it could also be done indpendently to the change of the internal implementation of LogicalaPlanBuilder
Looked at the conflict. It can be resolved by changing |
I took the liberty of merging this PR up from main to resolve the conflict |
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 @Dandandan and @jc4x4
I would be happy to merge this PR but I also think we could remove the clones in other ways that are smaller
However, in general, I think this PR improves the code / experience a bit so I think merging it is a good idea.
@@ -145,7 +150,7 @@ impl LogicalPlanBuilder { | |||
coerce_plan_expr_for_schema(&recursive_term, self.plan.schema())?; | |||
Ok(Self::from(LogicalPlan::RecursiveQuery(RecursiveQuery { | |||
name, | |||
static_term: Arc::new(self.plan.clone()), | |||
static_term: Arc::clone(&self.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.
FWIW I think we can avoid the clone by changing the signature from
pub fn to_recursive_query(
&self,
to
pub fn to_recursive_query(
self,
(the builder should be consumed)
@@ -145,7 +150,7 @@ impl LogicalPlanBuilder { | |||
coerce_plan_expr_for_schema(&recursive_term, self.plan.schema())?; | |||
Ok(Self::from(LogicalPlan::RecursiveQuery(RecursiveQuery { | |||
name, | |||
static_term: Arc::new(self.plan.clone()), | |||
static_term: Arc::clone(&self.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.
Another example in line 470.
I think since this is an associated function it could also be done indpendently to the change of the internal implementation of LogicalaPlanBuilder
Good catch. I've updated. |
Thanks again @jc4x4 |
Which issue does this PR close?
Closes #10485.
Rationale for this change
Refactor to avoid unnecessary copies of LogicalPlan.
What changes are included in this PR?
Update struct to use Arc. Verified test passes.
Used Arc::clone as much as I can; and unwrap_arc when a owned LogicalPlan is required.
Keep pub fn input unchanged as LogicalPlan to limit change scope. If we change the pub fn, we can also get rid of this pattern like below. If this broader change is wanted, I can follow up with a separate PR.
Are these changes tested?
Run unit tests inside builder.rs
Are there any user-facing changes?
No. Pub fn is explicitly not affected.