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: reduce cloning in infer_placeholder_types #5638

Merged
merged 1 commit into from
Mar 20, 2023

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Mar 18, 2023

Which issue does this PR close?

related to faster planning: #5637
related to like inference: #5617

Rationale for this change

This function has a bunch of unecessary clone() which likely means running parameter type inference would be bad to do for all queries

What changes are included in this PR?

Avoids a bunch of expr copies when inferring placeholder types

Are these changes tested?

Existing tests cover this functionality

Are there any user-facing changes?

No

@github-actions github-actions bot added the sql SQL Planner label Mar 18, 2023
@alamb alamb marked this pull request as ready for review March 18, 2023 16:23
@@ -78,7 +78,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
let mut expr = self.sql_expr_to_logical_expr(sql, schema, planner_context)?;
expr = self.rewrite_partial_qualifier(expr, schema);
self.validate_schema_satisfies_exprs(schema, &[expr.clone()])?;
let expr = infer_placeholder_types(expr, schema.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.

This cloned the schema as well as cloning all BinaryExprs

// Default to assuming the arguments are the same type
if let Expr::BinaryExpr(BinaryExpr { left, op: _, right }) = &mut expr {
rewrite_placeholder(left.as_mut(), right.as_ref(), schema)?;
rewrite_placeholder(right.as_mut(), left.as_ref(), schema)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Much more concise!

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! :)

@@ -417,6 +414,11 @@ impl DataFusionError {
// return last checkpoint (which may be the original error)
last_datafusion_error
}

/// wraps self in Self::Context with a description
pub fn context(self, description: impl Into<String>) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yay, thank you! I'm happy to see this being used and improved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it is really nice -- thanks for adding it!

// Default to assuming the arguments are the same type
if let Expr::BinaryExpr(BinaryExpr { left, op: _, right }) = &mut expr {
rewrite_placeholder(left.as_mut(), right.as_ref(), schema)?;
rewrite_placeholder(right.as_mut(), left.as_ref(), schema)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! :)

@alamb alamb changed the title Minor: reduce cloneing in infer_placeholder_types Minor: reduce cloning in infer_placeholder_types Mar 20, 2023
@alamb alamb merged commit 89f2102 into apache:main Mar 20, 2023
@alamb alamb deleted the alamb/less_copy2 branch July 26, 2024 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants