Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 29.4k
[SPARK-9306][SQL] Don't use SortMergeJoin when joining on unsortable columns#7645
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -36,9 +36,8 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] { | ||
| object LeftSemiJoin extends Strategy with PredicateHelper { | ||
| def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match { | ||
| case ExtractEquiJoinKeys(LeftSemi, leftKeys, rightKeys, condition, left, right) | ||
| if sqlContext.conf.autoBroadcastJoinThreshold > 0 && | ||
| right.statistics.sizeInBytes <= sqlContext.conf.autoBroadcastJoinThreshold => | ||
| case ExtractEquiJoinKeys( | ||
| LeftSemi, leftKeys, rightKeys, condition, left, CanBroadcast(right)) => | ||
MemberAuthor 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. We can use | ||
| joins.BroadcastLeftSemiJoinHash( | ||
| leftKeys, rightKeys, planLater(left), planLater(right), condition) :: Nil | ||
| // Find left semi joins where at least some predicates can be evaluated by matching join keys | ||
| @@ -91,6 +90,18 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] { | ||
| condition.map(Filter(_, broadcastHashJoin)).getOrElse(broadcastHashJoin) :: Nil | ||
| } | ||
| private[this] def isValidSort( | ||
| leftKeys: Seq[Expression], | ||
| rightKeys: Seq[Expression]): Boolean = { | ||
| leftKeys.zip(rightKeys).forall { keys => | ||
| (keys._1.dataType, keys._2.dataType) match { | ||
| case (l: AtomicType, r: AtomicType) => true | ||
| case (NullType, NullType) => true | ||
| case _ => false | ||
| } | ||
| } | ||
| } | ||
| def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match { | ||
| case ExtractEquiJoinKeys(Inner, leftKeys, rightKeys, condition, left, CanBroadcast(right)) => | ||
| makeBroadcastHashJoin(leftKeys, rightKeys, left, right, condition, joins.BuildRight) | ||
| @@ -101,7 +112,7 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] { | ||
| // If the sort merge join option is set, we want to use sort merge join prior to hashjoin | ||
| // for now let's support inner join first, then add outer join | ||
| case ExtractEquiJoinKeys(Inner, leftKeys, rightKeys, condition, left, right) | ||
| if sqlContext.conf.sortMergeJoinEnabled => | ||
| if sqlContext.conf.sortMergeJoinEnabled && isValidSort(leftKeys, rightKeys) => | ||
| val mergeJoin = | ||
| joins.SortMergeJoin(leftKeys, rightKeys, planLater(left), planLater(right)) | ||
| condition.map(Filter(_, mergeJoin)).getOrElse(mergeJoin) :: Nil | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -108,6 +108,18 @@ class JoinSuite extends QueryTest with BeforeAndAfterEach { | ||
| } | ||
| } | ||
| test("SortMergeJoin shouldn't work on unsortable columns") { | ||
| val SORTMERGEJOIN_ENABLED: Boolean = ctx.conf.sortMergeJoinEnabled | ||
| try { | ||
| ctx.conf.setConf(SQLConf.SORTMERGE_JOIN, true) | ||
| Seq( | ||
| ("SELECT * FROM arrayData JOIN complexData ON data = a", classOf[ShuffledHashJoin]) | ||
MemberAuthor 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.
| ||
| ).foreach { case (query, joinClass) => assertJoin(query, joinClass) } | ||
| } finally { | ||
| ctx.conf.setConf(SQLConf.SORTMERGE_JOIN, SORTMERGEJOIN_ENABLED) | ||
| } | ||
| } | ||
| test("broadcasted hash join operator selection") { | ||
| ctx.cacheManager.clearCache() | ||
| ctx.sql("CACHE TABLE testData") | ||
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.
Incorrect comment.