-
Notifications
You must be signed in to change notification settings - Fork 2k
Misc minor optimizations to query optimizer performance #21128
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
Draft
AdamGS
wants to merge
3
commits into
apache:main
Choose a base branch
from
AdamGS:adamg/optimizer-memory-optimizations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -320,10 +320,8 @@ fn can_evaluate_as_join_condition(predicate: &Expr) -> Result<bool> { | |
| /// * do nothing. | ||
| fn extract_or_clauses_for_join<'a>( | ||
| filters: &'a [Expr], | ||
| schema: &'a DFSchema, | ||
| schema_cols: &'a HashSet<Column>, | ||
| ) -> impl Iterator<Item = Expr> + 'a { | ||
| let schema_columns = schema_columns(schema); | ||
|
|
||
| // new formed OR clauses and their column references | ||
| filters.iter().filter_map(move |expr| { | ||
| if let Expr::BinaryExpr(BinaryExpr { | ||
|
|
@@ -332,8 +330,8 @@ fn extract_or_clauses_for_join<'a>( | |
| right, | ||
| }) = expr | ||
| { | ||
| let left_expr = extract_or_clause(left.as_ref(), &schema_columns); | ||
| let right_expr = extract_or_clause(right.as_ref(), &schema_columns); | ||
| let left_expr = extract_or_clause(left.as_ref(), schema_cols); | ||
| let right_expr = extract_or_clause(right.as_ref(), schema_cols); | ||
|
|
||
| // If nothing can be extracted from any sub clauses, do nothing for this OR clause. | ||
| if let (Some(left_expr), Some(right_expr)) = (left_expr, right_expr) { | ||
|
|
@@ -421,6 +419,10 @@ fn push_down_all_join( | |
| // 3) should be kept as filter conditions | ||
| let left_schema = join.left.schema(); | ||
| let right_schema = join.right.schema(); | ||
|
|
||
| let left_schema_columns = schema_columns(left_schema.as_ref()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there might be an even better thing here, but I need to do another pass |
||
| let right_schema_columns = schema_columns(right_schema.as_ref()); | ||
|
|
||
| let mut left_push = vec![]; | ||
| let mut right_push = vec![]; | ||
| let mut keep_predicates = vec![]; | ||
|
|
@@ -467,26 +469,38 @@ fn push_down_all_join( | |
| // Extract from OR clause, generate new predicates for both side of join if possible. | ||
| // We only track the unpushable predicates above. | ||
| if left_preserved { | ||
| left_push.extend(extract_or_clauses_for_join(&keep_predicates, left_schema)); | ||
| left_push.extend(extract_or_clauses_for_join(&join_conditions, left_schema)); | ||
| left_push.extend(extract_or_clauses_for_join( | ||
| &keep_predicates, | ||
| &left_schema_columns, | ||
| )); | ||
| left_push.extend(extract_or_clauses_for_join( | ||
| &join_conditions, | ||
| &left_schema_columns, | ||
| )); | ||
| } | ||
| if right_preserved { | ||
| right_push.extend(extract_or_clauses_for_join(&keep_predicates, right_schema)); | ||
| right_push.extend(extract_or_clauses_for_join(&join_conditions, right_schema)); | ||
| right_push.extend(extract_or_clauses_for_join( | ||
| &keep_predicates, | ||
| &right_schema_columns, | ||
| )); | ||
| right_push.extend(extract_or_clauses_for_join( | ||
| &join_conditions, | ||
| &right_schema_columns, | ||
| )); | ||
| } | ||
|
|
||
| // For predicates from join filter, we should check with if a join side is preserved | ||
| // in term of join filtering. | ||
| if on_left_preserved { | ||
| left_push.extend(extract_or_clauses_for_join( | ||
| &on_filter_join_conditions, | ||
| left_schema, | ||
| &left_schema_columns, | ||
| )); | ||
| } | ||
| if on_right_preserved { | ||
| right_push.extend(extract_or_clauses_for_join( | ||
| &on_filter_join_conditions, | ||
| right_schema, | ||
| &right_schema_columns, | ||
| )); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,12 +47,12 @@ impl OptimizerRule for PushDownLimit { | |
| true | ||
| } | ||
|
|
||
| #[expect(clippy::only_used_in_recursion)] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just wasteful, just a lint away. |
||
| fn rewrite( | ||
| &self, | ||
| plan: LogicalPlan, | ||
| config: &dyn OptimizerConfig, | ||
| ) -> Result<Transformed<LogicalPlan>> { | ||
| let _ = config.options(); | ||
| let LogicalPlan::Limit(mut limit) = plan else { | ||
| return Ok(Transformed::no(plan)); | ||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
empty DFSchema isn't free, similar to #20534