-
Notifications
You must be signed in to change notification settings - Fork 155
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
perf: Add option to replace SortMergeJoin with ShuffledHashJoin #1007
Open
andygrove
wants to merge
19
commits into
apache:main
Choose a base branch
from
andygrove:replace-smj
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.
+108
−2
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a1d04f5
experiment
andygrove 598735e
fix and add credit
andygrove d55f2ea
disable by default and make internal
andygrove e3313bd
remove sort
andygrove a0d1381
minor optimization
andygrove 948f2c0
minor optimization
andygrove fd87412
remove unused import
andygrove 99eca10
disable feature by default
andygrove 1d5b58d
fix dockerfile
andygrove 1a5de4e
Add section to tuning guide
andygrove 7cce6a5
update benchmarking guide
andygrove 8f5d440
Merge remote-tracking branch 'apache/main' into replace-smj
andygrove 7ce8726
Revert "chore: Reserve memory for native shuffle writer per partition…
andygrove 26f9a4f
mark feature as experimental and explain risks
andygrove 27a02af
upmerge
andygrove 63ce71c
workaround for TPC-DS q14 hanging on a RightSemi join
andygrove 60d1028
revert a change
andygrove 662d0de
remove debug logging:
andygrove 6ed01c1
format
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 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 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 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 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 |
---|---|---|
|
@@ -50,6 +50,7 @@ Comet provides the following configuration settings. | |
| spark.comet.exec.localLimit.enabled | Whether to enable localLimit by default. | true | | ||
| spark.comet.exec.memoryFraction | The fraction of memory from Comet memory overhead that the native memory manager can use for execution. The purpose of this config is to set aside memory for untracked data structures, as well as imprecise size estimation during memory acquisition. Default value is 0.7. | 0.7 | | ||
| spark.comet.exec.project.enabled | Whether to enable project by default. | true | | ||
| spark.comet.exec.replaceSortMergeJoin | Experimental feature to force Spark to replace SortMergeJoin with ShuffledHashJoin for improved performance. See tuning guide for more information regarding stability of this feature. | false | | ||
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. Can we add a link to the tuning guide? 🙏 |
||
| spark.comet.exec.shuffle.codec | The codec of Comet native shuffle used to compress shuffle data. Only zstd is supported. | zstd | | ||
| spark.comet.exec.shuffle.enabled | Whether to enable Comet native shuffle. Note that this requires setting 'spark.shuffle.manager' to 'org.apache.spark.sql.comet.execution.shuffle.CometShuffleManager'. 'spark.shuffle.manager' must be set before starting the Spark application and cannot be changed during the application. | true | | ||
| spark.comet.exec.sort.enabled | Whether to enable sort by default. | true | | ||
|
This file contains 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 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
70 changes: 70 additions & 0 deletions
70
spark/src/main/scala/org/apache/comet/rules/RewriteJoin.scala
This file contains 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.comet.rules | ||
|
||
import org.apache.spark.sql.catalyst.optimizer.{BuildLeft, BuildRight, BuildSide, JoinSelectionHelper} | ||
import org.apache.spark.sql.catalyst.plans.{JoinType, LeftSemi} | ||
import org.apache.spark.sql.execution.{SortExec, SparkPlan} | ||
import org.apache.spark.sql.execution.joins.{ShuffledHashJoinExec, SortMergeJoinExec} | ||
|
||
/** | ||
* Adapted from equivalent rule in Apache Gluten. | ||
* | ||
* This rule replaces [[SortMergeJoinExec]] with [[ShuffledHashJoinExec]]. | ||
*/ | ||
object RewriteJoin extends JoinSelectionHelper { | ||
|
||
private def getBuildSide(joinType: JoinType): Option[BuildSide] = { | ||
if (canBuildShuffledHashJoinRight(joinType)) { | ||
Some(BuildRight) | ||
} else if (canBuildShuffledHashJoinLeft(joinType)) { | ||
Some(BuildLeft) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
private def removeSort(plan: SparkPlan) = plan match { | ||
case _: SortExec => plan.children.head | ||
case _ => plan | ||
} | ||
|
||
def rewrite(plan: SparkPlan): SparkPlan = plan match { | ||
case smj: SortMergeJoinExec => | ||
getBuildSide(smj.joinType) match { | ||
case Some(BuildRight) if smj.joinType == LeftSemi => | ||
// TODO this was added as a workaround for TPC-DS q14 hanging and needs | ||
// further investigation | ||
plan | ||
case Some(buildSide) => | ||
ShuffledHashJoinExec( | ||
smj.leftKeys, | ||
smj.rightKeys, | ||
smj.joinType, | ||
buildSide, | ||
smj.condition, | ||
removeSort(smj.left), | ||
removeSort(smj.right), | ||
smj.isSkewJoin) | ||
case _ => plan | ||
} | ||
case _ => plan | ||
} | ||
} |
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.
Can we add a link to the tuning guide?