perf: Remove one redundant CopyExec for SMJ#962
Conversation
| is_sort_merge: bool, | ||
| plan: Arc<dyn ExecutionPlan>, | ||
| ) -> Arc<dyn ExecutionPlan> { | ||
| if is_sort_merge { |
There was a problem hiding this comment.
Is there a more general description for SMJ's property to name this variable, and then we could use this function for the duplicated code elsewhere in this file?
There was a problem hiding this comment.
Yes, I will refactor this to reduce duplication
|
edit: I ran the wrong script 🤦 |
|
A single run of TPC-DS comparing main to this PR does not show a significant difference (~1% difference). I did not expect this to make much difference, but it does remove a redundant operator and simplified the plan, |
| // 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)) | ||
| }; | ||
|
|
There was a problem hiding this comment.
This code is specific to HashJoinExec and not to SortMergeJoinExec, so I moved it out of this code, which is common to both joins.
mbutrovich
left a comment
There was a problem hiding this comment.
This a great catch, and a super clean refactor.
| } else { | ||
| Arc::new(CopyExec::new(child, CopyMode::UnpackOrClone)) | ||
| }; | ||
| let child = Self::wrap_in_copy_exec(child); |
There was a problem hiding this comment.
Can you add a similar comment here as you added with HashJoin on why Sort needs a CopyExec?
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> N/A ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> Apply OSS 0.3.0 changes. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ``` 84cccf7 docs: Add notes for IntelliJ code size limits for code inspections. (apache#985) dcc4a8a fix: The spilled_bytes metric of CometSortExec should be size instead of time (apache#984) f64553b chore: fix compatibility guide (apache#978) 0ee7df8 chore: Enable additional CreateArray tests (apache#928) a690e9d perf: Remove one redundant CopyExec for SMJ (apache#962) a8156b5 chore: update rem expression guide (apache#976) 317a534 fix: Use the number of rows from underlying arrays instead of logical row count from RecordBatch (apache#972) 22561c4 doc: add documentation interlinks (apache#975) b4de8e0 chore: Update benchmarks results based on 0.3.0-rc1 (apache#969) 94093f3 chore: fix publish-to-maven script (apache#966) f31f6cc Generate changelog for 0.3.0 release (apache#964) 5663fc2 fix: div and rem by negative zero (apache#960) 50517f6 perf: Optimize decimal precision check in decimal aggregates (sum and avg) (apache#952) 5b3f7bc fix: CometScanExec on Spark 3.5.2 (apache#915) 8410c71 chore: clarify tarball installation (apache#959) 459b2b0 fix: window function range offset should be long instead of int (apache#733) ``` ## How are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? -->
Which issue does this PR close?
N/A
Rationale for this change
We were injecting too many CopyExecs for SMJ. Plans looked like this:
What changes are included in this PR?
With the changes in this PR, the plan now looks like:
How are these changes tested?
Existing tests