-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Broadcast join if build estimation is small and from HBO #22681
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import com.facebook.presto.spi.plan.PlanNode; | ||
import com.facebook.presto.spi.plan.TableScanNode; | ||
import com.facebook.presto.spi.plan.ValuesNode; | ||
import com.facebook.presto.spi.statistics.HistoryBasedSourceInfo; | ||
import com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType; | ||
import com.facebook.presto.sql.planner.iterative.Lookup; | ||
import com.facebook.presto.sql.planner.iterative.Rule; | ||
|
@@ -126,7 +127,10 @@ private PlanNode getCostBasedJoin(JoinNode joinNode, Context context) | |
if (possibleJoinNodes.stream().anyMatch(result -> result.getCost().hasUnknownComponents()) || possibleJoinNodes.isEmpty()) { | ||
// TODO: currently this session parameter is added so as to roll out the plan change gradually, after proved to be a better choice, make it default and get rid of the session parameter here. | ||
if (isUseBroadcastJoinWhenBuildSizeSmallProbeSizeUnknownEnabled(context.getSession()) && possibleJoinNodes.stream().anyMatch(result -> ((JoinNode) result.getPlanNode()).getDistributionType().get().equals(REPLICATED))) { | ||
return getOnlyElement(possibleJoinNodes.stream().filter(result -> ((JoinNode) result.getPlanNode()).getDistributionType().get().equals(REPLICATED)).map(x -> x.getPlanNode()).collect(toImmutableList())); | ||
JoinNode broadcastJoin = (JoinNode) getOnlyElement(possibleJoinNodes.stream().filter(result -> ((JoinNode) result.getPlanNode()).getDistributionType().get().equals(REPLICATED)).map(x -> x.getPlanNode()).collect(toImmutableList())); | ||
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. nit: limit lines to 180 chars |
||
if (context.getStatsProvider().getStats(broadcastJoin.getBuild()).getSourceInfo() instanceof HistoryBasedSourceInfo) { | ||
return broadcastJoin; | ||
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. I think, in future whether the previous join was broadcast/hash and if it was efficient/or if it failed etc could also be stored using HBO |
||
} | ||
} | ||
if (isSizeBasedJoinDistributionTypeEnabled(context.getSession())) { | ||
return getSizeBasedJoin(joinNode, context); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
import com.facebook.presto.matching.Captures; | ||
import com.facebook.presto.matching.Pattern; | ||
import com.facebook.presto.spi.plan.PlanNode; | ||
import com.facebook.presto.spi.statistics.HistoryBasedSourceInfo; | ||
import com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType; | ||
import com.facebook.presto.sql.planner.iterative.Rule; | ||
import com.facebook.presto.sql.planner.plan.SemiJoinNode; | ||
|
@@ -48,11 +49,14 @@ | |
import static com.facebook.presto.SystemSessionProperties.getJoinDistributionType; | ||
import static com.facebook.presto.SystemSessionProperties.getJoinMaxBroadcastTableSize; | ||
import static com.facebook.presto.SystemSessionProperties.isSizeBasedJoinDistributionTypeEnabled; | ||
import static com.facebook.presto.SystemSessionProperties.isUseBroadcastJoinWhenBuildSizeSmallProbeSizeUnknownEnabled; | ||
import static com.facebook.presto.cost.CostCalculatorWithEstimatedExchanges.calculateJoinCostWithoutOutput; | ||
import static com.facebook.presto.sql.planner.iterative.rule.DetermineJoinDistributionType.getSourceTablesSizeInBytes; | ||
import static com.facebook.presto.sql.planner.plan.Patterns.semiJoin; | ||
import static com.facebook.presto.sql.planner.plan.SemiJoinNode.DistributionType.PARTITIONED; | ||
import static com.facebook.presto.sql.planner.plan.SemiJoinNode.DistributionType.REPLICATED; | ||
import static com.google.common.collect.ImmutableList.toImmutableList; | ||
import static com.google.common.collect.Iterables.getOnlyElement; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
|
@@ -124,6 +128,12 @@ private PlanNode getCostBasedDistributionType(SemiJoinNode node, Context context | |
possibleJoinNodes.add(getSemiJoinNodeWithCost(node.withDistributionType(PARTITIONED), context)); | ||
|
||
if (possibleJoinNodes.stream().anyMatch(result -> result.getCost().hasUnknownComponents())) { | ||
if (isUseBroadcastJoinWhenBuildSizeSmallProbeSizeUnknownEnabled(context.getSession()) && possibleJoinNodes.stream().anyMatch(result -> ((SemiJoinNode) result.getPlanNode()).getDistributionType().get().equals(REPLICATED))) { | ||
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. Also enable it for semi join |
||
SemiJoinNode broadcastJoin = (SemiJoinNode) getOnlyElement(possibleJoinNodes.stream().filter(result -> ((SemiJoinNode) result.getPlanNode()).getDistributionType().get().equals(REPLICATED)).map(x -> x.getPlanNode()).collect(toImmutableList())); | ||
if (context.getStatsProvider().getStats(broadcastJoin.getBuild()).getSourceInfo() instanceof HistoryBasedSourceInfo) { | ||
return broadcastJoin; | ||
} | ||
} | ||
if (isSizeBasedJoinDistributionTypeEnabled(context.getSession())) { | ||
return getSizeBaseDistributionType(node, context); | ||
} | ||
|
@@ -155,7 +165,7 @@ private boolean canReplicate(SemiJoinNode node, Context context) | |
PlanNodeStatsEstimate buildSideStatsEstimate = context.getStatsProvider().getStats(buildSide); | ||
double buildSideSizeInBytes = buildSideStatsEstimate.getOutputSizeInBytes(buildSide); | ||
return buildSideSizeInBytes <= joinMaxBroadcastTableSize.toBytes() | ||
|| (isSizeBasedJoinDistributionTypeEnabled(context.getSession()) | ||
|| (isSizeBasedJoinDistributionTypeEnabled(context.getSession()) | ||
&& getSourceTablesSizeInBytes(buildSide, context) <= joinMaxBroadcastTableSize.toBytes()); | ||
} | ||
|
||
|
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.
We should do it always - we trust history and if HBO says build side is small, we just broadcast it.
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.
This depends on whether the other side of the join is small or not, i.e. if both sides have estimations showing data size is small, whether we should do partitioned join or broadcast join. I think we can open a separate PR for this.