Skip to content

Commit 16fc60a

Browse files
Avoid calling statistics on plans if auto join conversion is disabled.
1 parent 8bd2816 commit 16fc60a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] {
2828

2929
// TODO: handle overflow?
3030
/**
31-
* Estimates of various statistics. The default estimation logic simply sums up the corresponding
32-
* statistic produced by the children. To override this behavior, override `statistics` and
33-
* assign it a overriden version of `Statistics`.
31+
* Estimates of various statistics. The default estimation logic simply lazily multiplies the
32+
* corresponding statistic produced by the children. To override this behavior, override
33+
* `statistics` and assign it an overriden version of `Statistics`.
3434
*
3535
* '''NOTE''': concrete and/or overriden versions of statistics fields should pay attention to the
3636
* performance of the implementations. The reason is that estimations might get triggered in

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] {
5858
* side in a [[execution.ShuffledHashJoin]].
5959
*/
6060
object HashJoin extends Strategy with PredicateHelper {
61-
private[this] def broadcastHashJoin(
61+
private[this] def makeBroadcastHashJoin(
6262
leftKeys: Seq[Expression],
6363
rightKeys: Seq[Expression],
6464
left: LogicalPlan,
@@ -72,12 +72,14 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] {
7272

7373
def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match {
7474
case ExtractEquiJoinKeys(Inner, leftKeys, rightKeys, condition, left, right)
75-
if right.statistics.sizeInBytes <= sqlContext.autoConvertJoinSize =>
76-
broadcastHashJoin(leftKeys, rightKeys, left, right, condition, BuildRight)
75+
if sqlContext.autoConvertJoinSize > 0 &&
76+
right.statistics.sizeInBytes <= sqlContext.autoConvertJoinSize =>
77+
makeBroadcastHashJoin(leftKeys, rightKeys, left, right, condition, BuildRight)
7778

7879
case ExtractEquiJoinKeys(Inner, leftKeys, rightKeys, condition, left, right)
79-
if left.statistics.sizeInBytes <= sqlContext.autoConvertJoinSize =>
80-
broadcastHashJoin(leftKeys, rightKeys, left, right, condition, BuildLeft)
80+
if sqlContext.autoConvertJoinSize > 0 &&
81+
left.statistics.sizeInBytes <= sqlContext.autoConvertJoinSize =>
82+
makeBroadcastHashJoin(leftKeys, rightKeys, left, right, condition, BuildLeft)
8183

8284
case ExtractEquiJoinKeys(Inner, leftKeys, rightKeys, condition, left, right) =>
8385
val buildSide =

0 commit comments

Comments
 (0)