-
Notifications
You must be signed in to change notification settings - Fork 304
perf: Remove one redundant CopyExec for SMJ #962
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3c87ee5
save
andygrove aa8f294
remove debug code
andygrove f401dd5
small refactor
andygrove b14497a
remove another CopyExec
andygrove b09ee52
revert changes to CopyExec
andygrove b252fc5
Revert "revert changes to CopyExec"
andygrove f9b0c49
Revert "remove another CopyExec"
andygrove 609a0fb
Revert some changes
andygrove 0e139e9
remove comment
andygrove cae1100
Revert a change
andygrove 9837d2c
cargo fmt
andygrove 31d0b0a
clippy
andygrove 5c9dbb8
refactor to avoid duplication
andygrove 8b7b468
address feedback
andygrove 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -917,15 +917,15 @@ impl PhysicalPlanner { | |
|
|
||
| let fetch = sort.fetch.map(|num| num as usize); | ||
|
|
||
| let copy_exec = if can_reuse_input_batch(&child) { | ||
| Arc::new(CopyExec::new(child, CopyMode::UnpackOrDeepCopy)) | ||
| } else { | ||
| Arc::new(CopyExec::new(child, CopyMode::UnpackOrClone)) | ||
| }; | ||
| // SortExec caches batches so we need to make a copy of incoming batches. Also, | ||
| // SortExec fails in some cases if we do not unpack dictionary-encoded arrays, and | ||
| // it would be more efficient if we could avoid that. | ||
| // https://github.com/apache/datafusion-comet/issues/963 | ||
| let child = Self::wrap_in_copy_exec(child); | ||
|
|
||
| Ok(( | ||
| scans, | ||
| Arc::new(SortExec::new(exprs?, copy_exec).with_fetch(fetch)), | ||
| Arc::new(SortExec::new(exprs?, child).with_fetch(fetch)), | ||
| )) | ||
| } | ||
| OpStruct::Scan(scan) => { | ||
|
|
@@ -1069,9 +1069,17 @@ impl PhysicalPlanner { | |
| join.join_type, | ||
| &join.condition, | ||
| )?; | ||
|
|
||
| // HashJoinExec may cache the input batch internally. We need | ||
| // to copy the input batch to avoid the data corruption from reusing the input | ||
| // batch. We also need to unpack dictionary arrays, because the join operators | ||
| // do not support them. | ||
| let left = Self::wrap_in_copy_exec(join_params.left); | ||
| let right = Self::wrap_in_copy_exec(join_params.right); | ||
|
|
||
| let hash_join = Arc::new(HashJoinExec::try_new( | ||
| join_params.left, | ||
| join_params.right, | ||
| left, | ||
| right, | ||
| join_params.join_on, | ||
| join_params.join_filter, | ||
| &join_params.join_type, | ||
|
|
@@ -1135,6 +1143,7 @@ impl PhysicalPlanner { | |
| } | ||
| } | ||
|
|
||
| #[allow(clippy::too_many_arguments)] | ||
| fn parse_join_parameters( | ||
| &self, | ||
| inputs: &mut Vec<Arc<GlobalRef>>, | ||
|
|
@@ -1263,21 +1272,6 @@ impl PhysicalPlanner { | |
| None | ||
| }; | ||
|
|
||
| // DataFusion Join operators keep the input batch internally. We need | ||
| // to copy the input batch to avoid the data corruption from reusing the input | ||
| // batch. | ||
| let left = if can_reuse_input_batch(&left) { | ||
| Arc::new(CopyExec::new(left, CopyMode::UnpackOrDeepCopy)) | ||
| } else { | ||
| Arc::new(CopyExec::new(left, CopyMode::UnpackOrClone)) | ||
| }; | ||
|
|
||
| let right = if can_reuse_input_batch(&right) { | ||
| Arc::new(CopyExec::new(right, CopyMode::UnpackOrDeepCopy)) | ||
| } else { | ||
| Arc::new(CopyExec::new(right, CopyMode::UnpackOrClone)) | ||
| }; | ||
|
|
||
|
Comment on lines
-1266
to
-1280
Member
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 code is specific to HashJoinExec and not to SortMergeJoinExec, so I moved it out of this code, which is common to both joins. |
||
| Ok(( | ||
| JoinParameters { | ||
| left, | ||
|
|
@@ -1290,6 +1284,16 @@ impl PhysicalPlanner { | |
| )) | ||
| } | ||
|
|
||
| /// Wrap an ExecutionPlan in a CopyExec, which will unpack any dictionary-encoded arrays | ||
| /// and make a deep copy of other arrays if the plan re-uses batches. | ||
| fn wrap_in_copy_exec(plan: Arc<dyn ExecutionPlan>) -> Arc<dyn ExecutionPlan> { | ||
| if can_reuse_input_batch(&plan) { | ||
| Arc::new(CopyExec::new(plan, CopyMode::UnpackOrDeepCopy)) | ||
| } else { | ||
| Arc::new(CopyExec::new(plan, CopyMode::UnpackOrClone)) | ||
| } | ||
| } | ||
|
|
||
| /// Create a DataFusion physical aggregate expression from Spark physical aggregate expression | ||
| fn create_agg_expr( | ||
| &self, | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Can you add a similar comment here as you added with HashJoin on why Sort needs a CopyExec?