-
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * 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.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 skew join aware implementation of [[Cost]], which consider shuffle number and skew join number | ||
| */ | ||
| 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. | ||
| */ | ||
| object SkewJoinAwareCostEvaluator extends CostEvaluator { | ||
| override def evaluateCost(plan: SparkPlan): Cost = { | ||
| val shuffleNumber = plan.collect { | ||
| case s: ShuffleExchangeLike => s | ||
| }.size | ||
| val skewJoinNumber = plan.collect { | ||
| case j: ShuffledJoin if j.isSkewJoin => j | ||
| }.size | ||
| SkewJoinAwareCost(shuffleNumber, skewJoinNumber) | ||
| } | ||
| } | ||
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.
is it mainly to exclude
OptimizeSkewedJoinin the final stage?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.
yea, currently it's only for OptimizeSkewedJoin