Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Apr 10, 2024

Which issue does this PR close?

Part of #9637 -- let's make DataFusion planning faster by not copying so much

Rationale for this change

Now that we have the nice TreeNode API thanks to #8913 and @peter-toth let's use it to both simplify the code and avoid copies

What changes are included in this PR?

Rewrite InlineTableScan using TreeNode API

Are these changes tested?

Existing CI

Are there any user-facing changes?

@alamb alamb marked this pull request as draft April 10, 2024 22:13
@github-actions github-actions bot added the optimizer Optimizer rules label Apr 10, 2024
Filter::try_new(new_expr, filter.input)
.map(|e| Transformed::yes(LogicalPlan::Filter(e)))
// rewrite any subqueries in the plan first
let result = plan.map_subqueries(|plan| plan.transform_up(&analyze_internal))?;
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 new API that @peter-toth added in #9913

}
})?;

fn rewrite_subquery(expr: Expr) -> Result<Transformed<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 now handled by apply_subqueries

fn rewrite_subquery(expr: Expr) -> Result<Transformed<Expr>> {
match expr {
Expr::Exists(Exists { subquery, negated }) => {
let plan = subquery.subquery.as_ref().clone();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these clones are avoided in the current formulation

@alamb alamb marked this pull request as ready for review April 10, 2024 22:54
Copy link
Contributor

@crepererum crepererum left a comment

Choose a reason for hiding this comment

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

Small readability nitpick.

Filter::try_new(new_expr, filter.input)
.map(|e| Transformed::yes(LogicalPlan::Filter(e)))
// rewrite any subqueries in the plan first
let result = plan.map_subqueries(|plan| plan.transform_up(&analyze_internal))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let result = plan.map_subqueries(|plan| plan.transform_up(&analyze_internal))?;
let plan = plan.map_subqueries(|plan| plan.transform_up(&analyze_internal))?;

When I read "result" I'm kinda expecting this to be a Result<_, _> which -- based on the result.transform_data call below -- is not the case here.

Same comment applies to the let result a few lines below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a good call -- renamed to transformed_plan in 0e0ac8e

@alamb
Copy link
Contributor Author

alamb commented Apr 12, 2024

Thanks again @crepererum

@alamb alamb merged commit a5cf0b8 into apache:main Apr 12, 2024
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.

2 participants