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

Minor: Avoid copying all expressions in Analzyer / check_plan #9974

Merged
merged 1 commit into from
Apr 7, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Apr 6, 2024

Which issue does this PR close?

Part of #9637

Rationale for this change

I found this while working on #9913 with @peter-toth

Calling LogicalPlan::expressions() does a copy of the expressions, but this function simply needs to check them

What changes are included in this PR?

  1. Use TreeNode API to visit expressions rather than LogicalPlan::expressions()

Are these changes tested?

Covered by existing unit tests

Are there any user-facing changes?

(Slightly) faster planning, and fewer copies during planning

@github-actions github-actions bot added the optimizer Optimizer rules label Apr 6, 2024
@@ -156,18 +155,21 @@ impl Analyzer {
/// Do necessary check and fail the invalid plan
fn check_plan(plan: &LogicalPlan) -> Result<()> {
plan.apply(&mut |plan: &LogicalPlan| {
for expr in plan.expressions().iter() {
plan.inspect_expressions(|expr| {
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 the line that voids a copy

Copy link
Member

Choose a reason for hiding this comment

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

A great catch! expressions() will invoke clone() inside, we can notice it to reduce some loss

Copy link
Contributor

@peter-toth peter-toth left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks @alamb!

Copy link
Contributor

@Jefffrey Jefffrey left a comment

Choose a reason for hiding this comment

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

👍

@jackwener jackwener merged commit f7b4ed0 into apache:main Apr 7, 2024
24 checks passed
@alamb alamb deleted the alamb/check_copy branch April 7, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimizer Optimizer rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants