-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33832][SQL] Support optimize skewed join even if introduce extra shuffle #32816
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
Changes from 1 commit
49e8bd9
db77ddd
a63cd72
59a5e4a
9c985da
e2102a5
8bc22ad
7734d3e
cbc7553
3dc61a3
30b7de0
6caa4a3
cd1a379
2b3bfe6
d305894
6725f97
7a0448b
60b7b9d
fbf9727
b54e9c2
f5ad40e
8058fe9
369bf33
d93c3df
b215e2d
5b63e4d
3ccc29b
bc45d70
580a0a4
bc39694
bb2e713
d3f0131
4712986
23ebea0
ef0765f
76c363d
8961084
5ba73c4
ca63321
f5e4b91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ package org.apache.spark.sql.execution.adaptive | |
| import org.apache.spark.sql.errors.QueryExecutionErrors | ||
| import org.apache.spark.sql.execution.SparkPlan | ||
| import org.apache.spark.sql.execution.exchange.ShuffleExchangeLike | ||
| import org.apache.spark.sql.execution.joins.ShuffledJoin | ||
|
|
||
| /** | ||
| * A simple implementation of [[Cost]], which takes a number of [[Long]] as the cost value. | ||
|
|
@@ -35,15 +36,44 @@ case class SimpleCost(value: Long) extends Cost { | |
| } | ||
|
|
||
| /** | ||
| * A simple implementation of [[CostEvaluator]], which counts the number of | ||
| * [[ShuffleExchangeLike]] nodes in the plan. | ||
| * A skew join aware implementation of [[Cost]], which consider shuffle number and skew join number | ||
|
||
| */ | ||
| object SimpleCostEvaluator extends CostEvaluator { | ||
| case class SkewJoinAwareCost( | ||
| numShuffles: Int, | ||
| numSkewJoins: Int) extends Cost { | ||
| override def compare(that: Cost): Int = that match { | ||
| case other: SkewJoinAwareCost => | ||
| if (numSkewJoins > other.numSkewJoins || numShuffles < other.numShuffles) { | ||
| // If more skew joins are optimized or less shuffle nodes, it means the cost is lower | ||
| -1 | ||
| } else if (numShuffles > other.numShuffles) { | ||
| 1 | ||
| } else { | ||
| 0 | ||
| } | ||
|
|
||
| case _ => | ||
| throw QueryExecutionErrors.cannotCompareCostWithTargetCostError(that.toString) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A skew join aware implementation of [[CostEvaluator]], which counts the number of | ||
| * [[ShuffleExchangeLike]] nodes and skew join nodes in the plan. | ||
| */ | ||
| case class SimpleCostEvaluator(forceOptimizeSkewedJoin: Boolean) extends CostEvaluator { | ||
| override def evaluateCost(plan: SparkPlan): Cost = { | ||
| val cost = plan.collect { | ||
| val shuffleNumber = plan.collect { | ||
| case s: ShuffleExchangeLike => s | ||
| }.size | ||
| SimpleCost(cost) | ||
|
|
||
| if (forceOptimizeSkewedJoin) { | ||
| val skewJoinNumber = plan.collect { | ||
|
||
| case j: ShuffledJoin if j.isSkewJoin => j | ||
| }.size | ||
| SkewJoinAwareCost(shuffleNumber, skewJoinNumber) | ||
| } else { | ||
| SimpleCost(shuffleNumber) | ||
| } | ||
| } | ||
| } | ||
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.
just move this code up