You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "wForget (via GitHub)" <gi...@apache.org> on 2026/03/13 07:48:51 UTC
[PR] [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin [spark]
wForget opened a new pull request, #41609:
URL: https://github.com/apache/spark/pull/41609
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
Split the skewed partitions of BroadcastHashJoin streamPlan when localShuffleReader is disabled.
+ Add `isSkewJoin` attribute in BroadcastHashJoinExec.
+ Handle skewed BroadcastHashJoinExec in `OptimizeSkewedJoin`.
+ Calculate skewed BroadcastHashJoinExec in `SimpleCostEvaluator.evaluateCost`.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
In RemoteShuffleService services such as uniffle and celeborn, it is recommended to disable localShuffleReader by default for better performance, but it may make BroadcastHashJoin skew again.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
new unit test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wForget commented on pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew when localShuffleReader is disabled
Posted by "wForget (via GitHub)" <gi...@apache.org>.
wForget commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-1619894072
> I think it makes sense to optimize skew with broadcast hash join. But it seems still useful when localShuffleReaderEnabled is enabled. Here is an attempt to resolve skewed partition with local shuffle reader, #40312.
I tried the test case in #40312. The optimized plan of OptimizeShuffleWithLocalRead is rolled back because there is a HashAggregate operation after BroadcastHashJoin which makes ValidateRequirements.validate fail.
The implementation of #40312 uses `OptimizeShuffleWithLocalRead.getPartitionSpecs` and `spark.sql.adaptive.forceOptimizeSkewedJoin=true` to make local shuffle read effective, but it will introduce additional shuffle, which seems not a good way.
How about we remove the localShuffleReaderEnabled judgment in the current implementation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on a diff in pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on code in PR #41609:
URL: https://github.com/apache/spark/pull/41609#discussion_r1270279601
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala:
##########
@@ -2851,6 +2851,68 @@ class AdaptiveQueryExecSuite
val unionDF = aggDf1.union(aggDf2)
checkAnswer(unionDF.select("id").distinct, Seq(Row(null)))
}
+
+ test("SPARK-44065: Optimize BroadcastHashJoin skew when localShuffleReader is disabled") {
+ withSQLConf(
+ SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.ADAPTIVE_AUTO_BROADCASTJOIN_THRESHOLD.key -> "1000",
+ SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> "false",
+ SQLConf.SHUFFLE_PARTITIONS.key -> "10",
+ SQLConf.SKEW_JOIN_SKEWED_PARTITION_THRESHOLD.key -> "600",
+ SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "600") {
+ withTempView("skewData", "smallData") {
+ spark
+ .range(0, 1000, 1, 10)
+ .selectExpr("if(id >= 5, 5, id) as key1", "id as value1")
+ .createOrReplaceTempView("skewData1")
+ spark
+ .range(0, 5, 1, 10)
+ .selectExpr("id key2", "id as value2")
+ .createOrReplaceTempView("smallData")
+
+ Seq(true, false).foreach { localShuffleReader =>
+ withSQLConf(SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> localShuffleReader.toString) {
+ val sqlText =
+ s"""
+ |select * from skewData1 a join smallData b on a.key1 = b.key2
+ |""".stripMargin
+ val (_, plan) = runAdaptiveAndVerifyResult(sqlText)
+ val bhjs = findTopLevelBroadcastHashJoin(plan)
+ assert(bhjs.nonEmpty)
+
+ if (localShuffleReader) {
+ val localShuffleReaders = collect(plan) {
+ case c: AQEShuffleReadExec if c.isLocalRead => c
Review Comment:
it seems not addressed, can you take a look ? @wForget
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin [spark]
Posted by "wForget (via GitHub)" <gi...@apache.org>.
wForget commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-3264785994
We have already ported it internally for a long time, and it works well. If needed, I’d be happy to continue working on it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wForget commented on a diff in pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "wForget (via GitHub)" <gi...@apache.org>.
wForget commented on code in PR #41609:
URL: https://github.com/apache/spark/pull/41609#discussion_r1271629202
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala:
##########
@@ -2851,6 +2851,68 @@ class AdaptiveQueryExecSuite
val unionDF = aggDf1.union(aggDf2)
checkAnswer(unionDF.select("id").distinct, Seq(Row(null)))
}
+
+ test("SPARK-44065: Optimize BroadcastHashJoin skew when localShuffleReader is disabled") {
+ withSQLConf(
+ SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.ADAPTIVE_AUTO_BROADCASTJOIN_THRESHOLD.key -> "1000",
+ SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> "false",
+ SQLConf.SHUFFLE_PARTITIONS.key -> "10",
+ SQLConf.SKEW_JOIN_SKEWED_PARTITION_THRESHOLD.key -> "600",
+ SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "600") {
+ withTempView("skewData", "smallData") {
+ spark
+ .range(0, 1000, 1, 10)
+ .selectExpr("if(id >= 5, 5, id) as key1", "id as value1")
+ .createOrReplaceTempView("skewData1")
+ spark
+ .range(0, 5, 1, 10)
+ .selectExpr("id key2", "id as value2")
+ .createOrReplaceTempView("smallData")
+
+ Seq(true, false).foreach { localShuffleReader =>
+ withSQLConf(SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> localShuffleReader.toString) {
+ val sqlText =
+ s"""
+ |select * from skewData1 a join smallData b on a.key1 = b.key2
+ |""".stripMargin
+ val (_, plan) = runAdaptiveAndVerifyResult(sqlText)
+ val bhjs = findTopLevelBroadcastHashJoin(plan)
+ assert(bhjs.nonEmpty)
+
+ if (localShuffleReader) {
+ val localShuffleReaders = collect(plan) {
+ case c: AQEShuffleReadExec if c.isLocalRead => c
Review Comment:
> it seems not addressed, can you take a look ? @wForget
Sorry, I'm still confused about this so belatedly did it. Do we still need to follow advisoryParallelism if we consider block size?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on a diff in pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on code in PR #41609:
URL: https://github.com/apache/spark/pull/41609#discussion_r1272916109
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeShuffleWithLocalRead.scala:
##########
@@ -139,7 +139,7 @@ object OptimizeShuffleWithLocalRead extends AQEShuffleReadRule {
def canUseLocalShuffleRead(plan: SparkPlan): Boolean = plan match {
case s: ShuffleQueryStageExec =>
s.mapStats.isDefined && isSupported(s.shuffle)
- case AQEShuffleReadExec(s: ShuffleQueryStageExec, _) =>
+ case a @ AQEShuffleReadExec(s: ShuffleQueryStageExec, _) if !a.hasSkewedPartition =>
Review Comment:
It won't cause skew if enable local shuffle read, so it just prevents the optimization.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewedJoin.scala:
##########
@@ -215,6 +237,18 @@ case class OptimizeSkewedJoin(ensureRequirements: EnsureRequirements)
case (newLeft, newRight) =>
shj.copy(left = newLeft, right = newRight, isSkewJoin = true)
}.getOrElse(shj)
+
+ case bhj @ BroadcastHashJoinExec(_, _, _, BuildRight, _,
+ ShuffleStage(left: ShuffleQueryStageExec), _, _, false) =>
Review Comment:
Add `LOCAL_SHUFFLE_READER_ENABLED` check here is better. The BHJ can only be skewed if local shuffle read is disabled. Then we do not need to touch rule `OptimizeShuffleWithLocalRead`.
Please add some comments about why we add this config check.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewedJoin.scala:
##########
@@ -215,6 +237,18 @@ case class OptimizeSkewedJoin(ensureRequirements: EnsureRequirements)
case (newLeft, newRight) =>
shj.copy(left = newLeft, right = newRight, isSkewJoin = true)
}.getOrElse(shj)
+
+ case bhj @ BroadcastHashJoinExec(_, _, _, BuildRight, _,
+ ShuffleStage(left: ShuffleQueryStageExec), _, _, false) =>
+ tryOptimizeBroadcastHashJoinStreamedPlan(left).map {
+ case newLeft => bhj.copy(left = newLeft, isSkewJoin = true)
+ }.getOrElse(bhj)
+
+ case bhj @ BroadcastHashJoinExec(_, _, _, BuildLeft, _, _,
+ ShuffleStage(right: ShuffleQueryStageExec), _, false) =>
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew when localShuffleReader is disabled
Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-1619603140
I see the issue, when a shuffle based join is converted to broadcast hash join in AQE, some partitions are going to be skewed due to shuffle. For shuffle based join, we have handled these skewed partitions by spliting and replicating other side. However, we did not do this optimization for broadcast hash join.
I think it makes sense to optimize skew with broadcast hash join. But it seems still useful when localShuffleReaderEnabled is enabled. Here is an attempt to resolve skewed partition with local shuffle reader, https://github.com/apache/spark/pull/40312.
Can we handle both of these two cases ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin [spark]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-4054592463
this is a super useful feature for the remote shuffle service case, where the shuffle data is stored at the remote (also, the data is not organized for efficient map-range read), rather than the local disk where the map task runs, thus localShuffleReader is not applicable.
cc more sql experts @cloud-fan @peter-toth @wangyum, could you please take a look? I know this patch was ported to many vendors' private branches, it would be great if we could have this in upstream.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin [spark]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-4053401682
@wForget, could you please rebase this PR one more time?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-1649463189
this change makes sense to me, cc @yaooqinn @wangyum @cloud-fan @dongjoon-hyun if you can take an another look
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-1937928464
We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin [spark]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-3264614219
cc @wForget @ulysses-you, can we evaluate this again?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wForget commented on pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew when localShuffleReader is disabled
Posted by "wForget (via GitHub)" <gi...@apache.org>.
wForget commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-1619428365
cc @cloud-fan @ulysses-you Could you please take a look?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew when localShuffleReader is disabled
Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-1620153650
I think we should handle it like what shuffle based join did. If it introduces extra shuffle then it should follow the behavior of force optimize skew join.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on a diff in pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on code in PR #41609:
URL: https://github.com/apache/spark/pull/41609#discussion_r1272923633
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewInRebalancePartitions.scala:
##########
@@ -39,34 +39,6 @@ object OptimizeSkewInRebalancePartitions extends AQEShuffleReadRule {
override val supportedShuffleOrigins: Seq[ShuffleOrigin] =
Seq(REBALANCE_PARTITIONS_BY_NONE, REBALANCE_PARTITIONS_BY_COL)
- /**
- * Splits the skewed partition based on the map size and the target partition size
- * after split. Create a list of `PartialReducerPartitionSpec` for skewed partition and
- * create `CoalescedPartition` for normal partition.
- */
- private def optimizeSkewedPartitions(
- shuffleId: Int,
- bytesByPartitionId: Array[Long],
- targetSize: Long): Seq[ShufflePartitionSpec] = {
- val smallPartitionFactor =
- conf.getConf(SQLConf.ADAPTIVE_REBALANCE_PARTITIONS_SMALL_PARTITION_FACTOR)
- bytesByPartitionId.indices.flatMap { reduceIndex =>
- val bytes = bytesByPartitionId(reduceIndex)
- if (bytes > targetSize) {
- val newPartitionSpec = ShufflePartitionsUtil.createSkewPartitionSpecs(
- shuffleId, reduceIndex, targetSize, smallPartitionFactor)
- if (newPartitionSpec.isEmpty) {
- CoalescedPartitionSpec(reduceIndex, reduceIndex + 1, bytes) :: Nil
- } else {
- logDebug(s"For shuffle $shuffleId, partition $reduceIndex is skew, " +
- s"split it into ${newPartitionSpec.get.size} parts.")
- newPartitionSpec.get
- }
- } else {
- CoalescedPartitionSpec(reduceIndex, reduceIndex + 1, bytes) :: Nil
- }
- }
- }
Review Comment:
Seems we can remove one more line
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on a diff in pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on code in PR #41609:
URL: https://github.com/apache/spark/pull/41609#discussion_r1253829679
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewedJoin.scala:
##########
@@ -198,6 +199,42 @@ case class OptimizeSkewedJoin(ensureRequirements: EnsureRequirements)
}
}
+ /**
+ * Split the skewed partition of the BroadcastHashJoin streamPlan.
+ */
+ private def tryOptimizeBroadcastHashJoinStreamedPlan(
+ shuffle: ShuffleQueryStageExec): Option[SparkPlan] = {
+ val mapStats = shuffle.mapStats.get
+ val bytesByPartitionId = mapStats.bytesByPartitionId
+ val medSize = Utils.median(bytesByPartitionId, false)
+ val skewThreshold = getSkewThreshold(medSize)
+ val streamedPlanTargetSize = targetSize(bytesByPartitionId, skewThreshold)
+
+ val newPartitionsSpec = bytesByPartitionId.indices.flatMap { reduceIndex =>
Review Comment:
Is there have existed code can be reused ? We can put it to `ShufflePartitionsUtil`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-1791732437
We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wForget commented on a diff in pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "wForget (via GitHub)" <gi...@apache.org>.
wForget commented on code in PR #41609:
URL: https://github.com/apache/spark/pull/41609#discussion_r1271781218
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala:
##########
@@ -2851,6 +2851,68 @@ class AdaptiveQueryExecSuite
val unionDF = aggDf1.union(aggDf2)
checkAnswer(unionDF.select("id").distinct, Seq(Row(null)))
}
+
+ test("SPARK-44065: Optimize BroadcastHashJoin skew when localShuffleReader is disabled") {
+ withSQLConf(
+ SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.ADAPTIVE_AUTO_BROADCASTJOIN_THRESHOLD.key -> "1000",
+ SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> "false",
+ SQLConf.SHUFFLE_PARTITIONS.key -> "10",
+ SQLConf.SKEW_JOIN_SKEWED_PARTITION_THRESHOLD.key -> "600",
+ SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "600") {
+ withTempView("skewData", "smallData") {
+ spark
+ .range(0, 1000, 1, 10)
+ .selectExpr("if(id >= 5, 5, id) as key1", "id as value1")
+ .createOrReplaceTempView("skewData1")
+ spark
+ .range(0, 5, 1, 10)
+ .selectExpr("id key2", "id as value2")
+ .createOrReplaceTempView("smallData")
+
+ Seq(true, false).foreach { localShuffleReader =>
+ withSQLConf(SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> localShuffleReader.toString) {
+ val sqlText =
+ s"""
+ |select * from skewData1 a join smallData b on a.key1 = b.key2
+ |""".stripMargin
+ val (_, plan) = runAdaptiveAndVerifyResult(sqlText)
+ val bhjs = findTopLevelBroadcastHashJoin(plan)
+ assert(bhjs.nonEmpty)
+
+ if (localShuffleReader) {
+ val localShuffleReaders = collect(plan) {
+ case c: AQEShuffleReadExec if c.isLocalRead => c
Review Comment:
I have skipped optimization in `OptimizeShuffleWithLocalRead` for `AQEShuffleReadExec` with skewed partitions. What do you think of this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin [spark]
Posted by "cxzl25 (via GitHub)" <gi...@apache.org>.
cxzl25 commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-3268841111
I have verified that in production environment, using Celeborn works well when BHJ has skew. cc @mridulm @waitinfuture
---
<img width="738" height="576" alt="image" src="https://github.com/user-attachments/assets/c366b654-3d81-4046-8386-3b304e128bcd" />
---
https://github.com/apache/celeborn/issues/1712
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wForget commented on a diff in pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "wForget (via GitHub)" <gi...@apache.org>.
wForget commented on code in PR #41609:
URL: https://github.com/apache/spark/pull/41609#discussion_r1271653709
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala:
##########
@@ -2851,6 +2851,68 @@ class AdaptiveQueryExecSuite
val unionDF = aggDf1.union(aggDf2)
checkAnswer(unionDF.select("id").distinct, Seq(Row(null)))
}
+
+ test("SPARK-44065: Optimize BroadcastHashJoin skew when localShuffleReader is disabled") {
+ withSQLConf(
+ SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.ADAPTIVE_AUTO_BROADCASTJOIN_THRESHOLD.key -> "1000",
+ SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> "false",
+ SQLConf.SHUFFLE_PARTITIONS.key -> "10",
+ SQLConf.SKEW_JOIN_SKEWED_PARTITION_THRESHOLD.key -> "600",
+ SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "600") {
+ withTempView("skewData", "smallData") {
+ spark
+ .range(0, 1000, 1, 10)
+ .selectExpr("if(id >= 5, 5, id) as key1", "id as value1")
+ .createOrReplaceTempView("skewData1")
+ spark
+ .range(0, 5, 1, 10)
+ .selectExpr("id key2", "id as value2")
+ .createOrReplaceTempView("smallData")
+
+ Seq(true, false).foreach { localShuffleReader =>
+ withSQLConf(SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> localShuffleReader.toString) {
+ val sqlText =
+ s"""
+ |select * from skewData1 a join smallData b on a.key1 = b.key2
+ |""".stripMargin
+ val (_, plan) = runAdaptiveAndVerifyResult(sqlText)
+ val bhjs = findTopLevelBroadcastHashJoin(plan)
+ assert(bhjs.nonEmpty)
+
+ if (localShuffleReader) {
+ val localShuffleReaders = collect(plan) {
+ case c: AQEShuffleReadExec if c.isLocalRead => c
Review Comment:
Do you mean we don't need `OptimizeShuffleWithLocalRead` optimization when there are `PartialReducerPartitionSpec`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wForget commented on pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "wForget (via GitHub)" <gi...@apache.org>.
wForget commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-1621080029
> I think we should handle it like what shuffle based join did. If it introduces extra shuffle then it should follow the behavior of force optimize skew join.
Thanks @ulysses-you . I have optimized BroadcastHashJoin like what shuffle based join did and removed the judgment of localShuffleReader to cover the case in #40312.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
URL: https://github.com/apache/spark/pull/41609
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on a diff in pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on code in PR #41609:
URL: https://github.com/apache/spark/pull/41609#discussion_r1271643468
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala:
##########
@@ -2851,6 +2851,68 @@ class AdaptiveQueryExecSuite
val unionDF = aggDf1.union(aggDf2)
checkAnswer(unionDF.select("id").distinct, Seq(Row(null)))
}
+
+ test("SPARK-44065: Optimize BroadcastHashJoin skew when localShuffleReader is disabled") {
+ withSQLConf(
+ SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.ADAPTIVE_AUTO_BROADCASTJOIN_THRESHOLD.key -> "1000",
+ SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> "false",
+ SQLConf.SHUFFLE_PARTITIONS.key -> "10",
+ SQLConf.SKEW_JOIN_SKEWED_PARTITION_THRESHOLD.key -> "600",
+ SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "600") {
+ withTempView("skewData", "smallData") {
+ spark
+ .range(0, 1000, 1, 10)
+ .selectExpr("if(id >= 5, 5, id) as key1", "id as value1")
+ .createOrReplaceTempView("skewData1")
+ spark
+ .range(0, 5, 1, 10)
+ .selectExpr("id key2", "id as value2")
+ .createOrReplaceTempView("smallData")
+
+ Seq(true, false).foreach { localShuffleReader =>
+ withSQLConf(SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> localShuffleReader.toString) {
+ val sqlText =
+ s"""
+ |select * from skewData1 a join smallData b on a.key1 = b.key2
+ |""".stripMargin
+ val (_, plan) = runAdaptiveAndVerifyResult(sqlText)
+ val bhjs = findTopLevelBroadcastHashJoin(plan)
+ assert(bhjs.nonEmpty)
+
+ if (localShuffleReader) {
+ val localShuffleReaders = collect(plan) {
+ case c: AQEShuffleReadExec if c.isLocalRead => c
Review Comment:
We should respect `PartialReducerPartitionSpec` in `OptimizeShuffleWithLocalRead`. Before this pr, `OptimizeShuffleWithLocalRead` assumes it would not accpet the skewed partition, so we should make it consider `PartialReducerPartitionSpec`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on a diff in pull request #41609: [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin
Posted by "ulysses-you (via GitHub)" <gi...@apache.org>.
ulysses-you commented on code in PR #41609:
URL: https://github.com/apache/spark/pull/41609#discussion_r1253820018
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewedJoin.scala:
##########
@@ -215,6 +252,18 @@ case class OptimizeSkewedJoin(ensureRequirements: EnsureRequirements)
case (newLeft, newRight) =>
shj.copy(left = newLeft, right = newRight, isSkewJoin = true)
}.getOrElse(shj)
+
+ case bhj @ BroadcastHashJoinExec(_, _, _, BuildRight, _,
+ ShuffleStage(left: ShuffleQueryStageExec), _, _, _) =>
+ tryOptimizeBroadcastHashJoinStreamedPlan(left).map {
+ case newLeft => bhj.copy(left = newLeft, isSkewJoin = true)
+ }.getOrElse(bhj)
+
+ case bhj @ BroadcastHashJoinExec(_, _, _, BuildLeft, _, _,
+ ShuffleStage(right: ShuffleQueryStageExec), _, _) =>
Review Comment:
```suggestion
ShuffleStage(right: ShuffleQueryStageExec), _, false) =>
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala:
##########
@@ -2851,6 +2851,68 @@ class AdaptiveQueryExecSuite
val unionDF = aggDf1.union(aggDf2)
checkAnswer(unionDF.select("id").distinct, Seq(Row(null)))
}
+
+ test("SPARK-44065: Optimize BroadcastHashJoin skew when localShuffleReader is disabled") {
+ withSQLConf(
+ SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
+ SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1",
+ SQLConf.ADAPTIVE_AUTO_BROADCASTJOIN_THRESHOLD.key -> "1000",
+ SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> "false",
+ SQLConf.SHUFFLE_PARTITIONS.key -> "10",
+ SQLConf.SKEW_JOIN_SKEWED_PARTITION_THRESHOLD.key -> "600",
+ SQLConf.ADVISORY_PARTITION_SIZE_IN_BYTES.key -> "600") {
+ withTempView("skewData", "smallData") {
+ spark
+ .range(0, 1000, 1, 10)
+ .selectExpr("if(id >= 5, 5, id) as key1", "id as value1")
+ .createOrReplaceTempView("skewData1")
+ spark
+ .range(0, 5, 1, 10)
+ .selectExpr("id key2", "id as value2")
+ .createOrReplaceTempView("smallData")
+
+ Seq(true, false).foreach { localShuffleReader =>
+ withSQLConf(SQLConf.LOCAL_SHUFFLE_READER_ENABLED.key -> localShuffleReader.toString) {
+ val sqlText =
+ s"""
+ |select * from skewData1 a join smallData b on a.key1 = b.key2
+ |""".stripMargin
+ val (_, plan) = runAdaptiveAndVerifyResult(sqlText)
+ val bhjs = findTopLevelBroadcastHashJoin(plan)
+ assert(bhjs.nonEmpty)
+
+ if (localShuffleReader) {
+ val localShuffleReaders = collect(plan) {
+ case c: AQEShuffleReadExec if c.isLocalRead => c
Review Comment:
I think there is a issue with local shuffle read. Before, the rule `OptimizeShuffleWithLocalRead#getPartitionSpecs` assume all the shuffle block are the same data size, https://github.com/apache/spark/blob/29e09473a816f1cb0ddea3e49d6dcb492ad473d9/sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeShuffleWithLocalRead.scala#L67-L69
but now the assumption is broken. We should update the code to consider skewed partitions, otherwise it can be still skewed when enabled local shuffle read.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewedJoin.scala:
##########
@@ -215,6 +252,18 @@ case class OptimizeSkewedJoin(ensureRequirements: EnsureRequirements)
case (newLeft, newRight) =>
shj.copy(left = newLeft, right = newRight, isSkewJoin = true)
}.getOrElse(shj)
+
+ case bhj @ BroadcastHashJoinExec(_, _, _, BuildRight, _,
+ ShuffleStage(left: ShuffleQueryStageExec), _, _, _) =>
Review Comment:
```suggestion
ShuffleStage(left: ShuffleQueryStageExec), _, _, false) =>
```
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala:
##########
@@ -2851,6 +2851,68 @@ class AdaptiveQueryExecSuite
val unionDF = aggDf1.union(aggDf2)
checkAnswer(unionDF.select("id").distinct, Seq(Row(null)))
}
+
+ test("SPARK-44065: Optimize BroadcastHashJoin skew when localShuffleReader is disabled") {
Review Comment:
test name should be changed
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewedJoin.scala:
##########
@@ -198,6 +199,42 @@ case class OptimizeSkewedJoin(ensureRequirements: EnsureRequirements)
}
}
+ /**
+ * Split the skewed partition of the BroadcastHashJoin streamPlan.
+ */
+ private def tryOptimizeBroadcastHashJoinStreamedPlan(
+ shuffle: ShuffleQueryStageExec): Option[SparkPlan] = {
+ val mapStats = shuffle.mapStats.get
+ val bytesByPartitionId = mapStats.bytesByPartitionId
+ val medSize = Utils.median(bytesByPartitionId, false)
+ val skewThreshold = getSkewThreshold(medSize)
+ val streamedPlanTargetSize = targetSize(bytesByPartitionId, skewThreshold)
+
+ val newPartitionsSpec = bytesByPartitionId.indices.flatMap { reduceIndex =>
Review Comment:
Is there existed code can be reused ? We can put it to `ShufflePartitionsUtil`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-44065][SQL] Optimize BroadcastHashJoin skew in OptimizeSkewedJoin [spark]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #41609:
URL: https://github.com/apache/spark/pull/41609#issuecomment-4073653823
thank you @peter-toth! I will merge this after 24h if there are no more comments from other reviewers
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org