You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "wangyum (via GitHub)" <gi...@apache.org> on 2025/02/19 09:18:11 UTC
[PR] [SPARK-51256][SQL] Increase parallelism if joining with small bucket table [spark]
wangyum opened a new pull request, #50004:
URL: https://github.com/apache/spark/pull/50004
### What changes were proposed in this pull request?
Increase parallelism if joining with small bucket table.
### Why are the changes needed?
Improve query performance.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Unit test.
### Was this patch authored or co-authored using generative AI tooling?
No.
--
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-51256][SQL] Increase parallelism if joining with small bucket table [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #50004:
URL: https://github.com/apache/spark/pull/50004#discussion_r1967710205
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala:
##########
@@ -150,10 +150,15 @@ case class EnsureRequirements(
// A: (No_Exchange, 100) <---> B: (Exchange, 120)
// it's better to pick A and change B to (Exchange, 100) instead of picking B and insert a
// new shuffle for A.
Review Comment:
Can we update this code comment w.r.t. the new change?
--
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-51256][SQL] Increase parallelism if joining with small bucket table [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #50004:
URL: https://github.com/apache/spark/pull/50004#issuecomment-2964622136
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-51256][SQL] Increase parallelism if joining with small bucket table [spark]
Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on code in PR #50004:
URL: https://github.com/apache/spark/pull/50004#discussion_r1970850047
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala:
##########
@@ -150,10 +150,15 @@ case class EnsureRequirements(
// A: (No_Exchange, 100) <---> B: (Exchange, 120)
// it's better to pick A and change B to (Exchange, 100) instead of picking B and insert a
// new shuffle for A.
- val candidateSpecsWithoutShuffle = candidateSpecs.filter { case (k, _) =>
- !children(k).isInstanceOf[ShuffleExchangeLike]
+ val (candidateSpecsWithShuffle, candidateSpecsWithoutShuffle) = candidateSpecs.partition {
+ case (k, _) => children(k).isInstanceOf[ShuffleExchangeLike]
}
- val finalCandidateSpecs = if (candidateSpecsWithoutShuffle.nonEmpty) {
+ val maxShufflePartNumOpt = candidateSpecsWithShuffle.values.map(_.numPartitions).maxOption
+ val finalCandidateSpecs = if (candidateSpecsWithoutShuffle.nonEmpty &&
+ maxShufflePartNumOpt.forall { n =>
+ n / candidateSpecsWithoutShuffle.values.map(_.numPartitions).max <=
+ conf.coalesceBucketsInJoinMaxBucketRatio
Review Comment:
https://github.com/apache/spark/blob/498519ee6bb4b0295d1df005175e4cbcbcb051e3/sql/core/src/main/scala/org/apache/spark/sql/execution/bucketing/CoalesceBucketsInJoin.scala#L89-L90
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala:
##########
@@ -150,10 +150,15 @@ case class EnsureRequirements(
// A: (No_Exchange, 100) <---> B: (Exchange, 120)
// it's better to pick A and change B to (Exchange, 100) instead of picking B and insert a
// new shuffle for A.
Review Comment:
👌
--
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-51256][SQL] Increase parallelism if joining with small bucket table [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #50004: [SPARK-51256][SQL] Increase parallelism if joining with small bucket table
URL: https://github.com/apache/spark/pull/50004
--
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-51256][SQL] Increase parallelism if joining with small bucket table [spark]
Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on PR #50004:
URL: https://github.com/apache/spark/pull/50004#issuecomment-2668112328
cc @sunchao @cloud-fan
--
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-51256][SQL] Increase parallelism if joining with small bucket table [spark]
Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on PR #50004:
URL: https://github.com/apache/spark/pull/50004#issuecomment-2677280562
```scala
spark.sql("set spark.sql.autoBroadcastJoinThreshold=-1")
spark.range(10000000).selectExpr("id", "id + 1 as new_id").write.saveAsTable("t1")
spark.range(10).selectExpr("id").write.bucketBy(1, "id").saveAsTable("t2")
spark.sql("select * from t1 join t2 on t1.id = t2.id").explain("cost")
```
Spark 3.2:
```
== Physical Plan ==
AdaptiveSparkPlan isFinalPlan=false
+- SortMergeJoin [id#21L], [id#23L], Inner
:- Sort [id#21L ASC NULLS FIRST], false, 0
: +- Exchange hashpartitioning(id#21L, 200), ENSURE_REQUIREMENTS, [plan_id=50]
: +- Filter isnotnull(id#21L)
: +- FileScan parquet default.t1[id#21L,new_id#22L] Batched: true, DataFilters: [isnotnull(id#21L)], Format: Parquet, Location: InMemoryFileIndex(1 paths)[file:/Users/yumwang/Downloads/spark-3.2.4-bin-hadoop3.2/spark-warehous..., PartitionFilters: [], PushedFilters: [IsNotNull(id)], ReadSchema: struct<id:bigint,new_id:bigint>
+- Sort [id#23L ASC NULLS FIRST], false, 0
+- Exchange hashpartitioning(id#23L, 200), ENSURE_REQUIREMENTS, [plan_id=57]
+- Filter isnotnull(id#23L)
+- FileScan parquet default.t2[id#23L] Batched: true, DataFilters: [isnotnull(id#23L)], Format: Parquet, Location: InMemoryFileIndex(1 paths)[file:/Users/yumwang/Downloads/spark-3.2.4-bin-hadoop3.2/spark-warehous..., PartitionFilters: [], PushedFilters: [IsNotNull(id)], ReadSchema: struct<id:bigint>
```
After Spark 3.3:
```
== Physical Plan ==
AdaptiveSparkPlan isFinalPlan=false
+- SortMergeJoin [id#21L], [id#23L], Inner
:- Sort [id#21L ASC NULLS FIRST], false, 0
: +- Exchange hashpartitioning(id#21L, 1), ENSURE_REQUIREMENTS, [plan_id=51]
: +- Filter isnotnull(id#21L)
: +- FileScan parquet default.t1[id#21L,new_id#22L] Batched: true, DataFilters: [isnotnull(id#21L)], Format: Parquet, Location: InMemoryFileIndex(1 paths)[file:/Users/yumwang/Downloads/spark-3.3.3-bin-hadoop3/spark-warehouse/t1], PartitionFilters: [], PushedFilters: [IsNotNull(id)], ReadSchema: struct<id:bigint,new_id:bigint>
+- Sort [id#23L ASC NULLS FIRST], false, 0
+- Filter isnotnull(id#23L)
+- FileScan parquet default.t2[id#23L] Batched: true, Bucketed: true, DataFilters: [isnotnull(id#23L)], Format: Parquet, Location: InMemoryFileIndex(1 paths)[file:/Users/yumwang/Downloads/spark-3.3.3-bin-hadoop3/spark-warehouse/t2], PartitionFilters: [], PushedFilters: [IsNotNull(id)], ReadSchema: struct<id:bigint>, SelectedBucketsCount: 1 out of 1
```
--
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-51256][SQL] Increase parallelism if joining with small bucket table [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #50004:
URL: https://github.com/apache/spark/pull/50004#discussion_r1967730371
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala:
##########
@@ -150,10 +150,15 @@ case class EnsureRequirements(
// A: (No_Exchange, 100) <---> B: (Exchange, 120)
// it's better to pick A and change B to (Exchange, 100) instead of picking B and insert a
// new shuffle for A.
- val candidateSpecsWithoutShuffle = candidateSpecs.filter { case (k, _) =>
- !children(k).isInstanceOf[ShuffleExchangeLike]
+ val (candidateSpecsWithShuffle, candidateSpecsWithoutShuffle) = candidateSpecs.partition {
+ case (k, _) => children(k).isInstanceOf[ShuffleExchangeLike]
}
- val finalCandidateSpecs = if (candidateSpecsWithoutShuffle.nonEmpty) {
+ val maxShufflePartNumOpt = candidateSpecsWithShuffle.values.map(_.numPartitions).maxOption
+ val finalCandidateSpecs = if (candidateSpecsWithoutShuffle.nonEmpty &&
+ maxShufflePartNumOpt.forall { n =>
+ n / candidateSpecsWithoutShuffle.values.map(_.numPartitions).max <=
+ conf.coalesceBucketsInJoinMaxBucketRatio
Review Comment:
just for my education, where else do we read this conf?
--
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