-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-10484][SQL] Optimize the cartesian join with broadcast join for some cases #8652
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -294,25 +294,24 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] { | |
| } | ||
| } | ||
|
|
||
|
|
||
| object BroadcastNestedLoopJoin extends Strategy { | ||
| object BroadcastNestedLoop extends Strategy { | ||
|
Contributor
Author
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. The renaming is intended, as some of the users will extends the |
||
| def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match { | ||
| case logical.Join(left, right, joinType, condition) => | ||
| val buildSide = | ||
| if (right.statistics.sizeInBytes <= left.statistics.sizeInBytes) { | ||
| joins.BuildRight | ||
| } else { | ||
| joins.BuildLeft | ||
| } | ||
| joins.BroadcastNestedLoopJoin( | ||
| planLater(left), planLater(right), buildSide, joinType, condition) :: Nil | ||
| case logical.Join( | ||
| CanBroadcast(left), right, joinType, condition) if joinType != LeftSemiJoin => | ||
| execution.joins.BroadcastNestedLoopJoin( | ||
| planLater(left), planLater(right), joins.BuildLeft, joinType, condition) :: Nil | ||
| case logical.Join( | ||
| left, CanBroadcast(right), joinType, condition) if joinType != LeftSemiJoin => | ||
| execution.joins.BroadcastNestedLoopJoin( | ||
| planLater(left), planLater(right), joins.BuildRight, joinType, condition) :: Nil | ||
| case _ => Nil | ||
| } | ||
| } | ||
|
|
||
| object CartesianProduct extends Strategy { | ||
| def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match { | ||
| case logical.Join(left, right, _, None) => | ||
| // TODO CartesianProduct doesn't support the Left Semi Join | ||
| case logical.Join(left, right, joinType, None) if joinType != LeftSemiJoin => | ||
| execution.joins.CartesianProduct(planLater(left), planLater(right)) :: Nil | ||
| case logical.Join(left, right, Inner, Some(condition)) => | ||
| execution.Filter(condition, | ||
|
|
@@ -321,6 +320,21 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] { | |
| } | ||
| } | ||
|
|
||
| object DefaultJoin extends Strategy { | ||
|
Contributor
Author
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. Add the new rule object, for the real last gate, for now, it actually will generate the |
||
| def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match { | ||
| case logical.Join(left, right, joinType, condition) => | ||
| val buildSide = | ||
| if (right.statistics.sizeInBytes <= left.statistics.sizeInBytes) { | ||
| joins.BuildRight | ||
| } else { | ||
| joins.BuildLeft | ||
| } | ||
| joins.BroadcastNestedLoopJoin( | ||
| planLater(left), planLater(right), buildSide, joinType, condition) :: Nil | ||
| case _ => Nil | ||
| } | ||
| } | ||
|
|
||
| protected lazy val singleRowRdd = sparkContext.parallelize(Seq(InternalRow()), 1) | ||
|
|
||
| object TakeOrderedAndProject extends Strategy { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| 302 0 | ||
| 302 0 | ||
| 302 0 | ||
| 305 0 | ||
| 305 0 | ||
| 305 0 | ||
| 306 0 | ||
| 306 0 | ||
| 306 0 | ||
| 307 0 | ||
| 307 0 | ||
| 307 0 | ||
| 307 0 | ||
| 307 0 | ||
| 307 0 | ||
| 308 0 | ||
| 308 0 | ||
| 308 0 | ||
| 309 0 | ||
| 309 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| 302 0 | ||
| 302 0 | ||
| 302 0 | ||
| 305 0 | ||
| 305 0 | ||
| 305 0 | ||
| 305 2 | ||
| 305 4 | ||
| 306 0 | ||
| 306 0 | ||
| 306 0 | ||
| 306 2 | ||
| 306 4 | ||
| 306 5 | ||
| 306 5 | ||
| 306 5 | ||
| 307 0 | ||
| 307 0 | ||
| 307 0 | ||
| 307 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| 302 0 | ||
| 302 0 | ||
| 302 0 | ||
| 305 0 | ||
| 305 0 | ||
| 305 0 | ||
| 305 2 | ||
| 305 4 | ||
| 306 0 | ||
| 306 0 | ||
| 306 0 | ||
| 306 2 | ||
| 306 4 | ||
| 306 5 | ||
| 306 5 | ||
| 306 5 | ||
| 307 0 | ||
| 307 0 | ||
| 307 0 | ||
| 307 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| 302 0 | ||
| 302 0 | ||
| 302 0 | ||
| 305 0 | ||
| 305 0 | ||
| 305 0 | ||
| 305 2 | ||
| 305 4 | ||
| 306 0 | ||
| 306 0 | ||
| 306 0 | ||
| 306 2 | ||
| 306 4 | ||
| 306 5 | ||
| 306 5 | ||
| 306 5 | ||
| 307 0 | ||
| 307 0 | ||
| 307 0 | ||
| 307 0 |
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.
Add a the
BroadcastNestedLoop, which should be prior toCartesianProduct.