-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add null stats for join probe #21203
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 |
|---|---|---|
|
|
@@ -193,6 +193,7 @@ private static class Rewriter | |
| extends SimplePlanRewriter<Set<VariableReferenceExpression>> | ||
| { | ||
| private static final double NULL_BUILD_KEY_COUNT_THRESHOLD = 100_000; | ||
| private static final double NULL_PROBE_KEY_COUNT_THRESHOLD = 100_000; | ||
| private static final String LEFT_PREFIX = "l"; | ||
| private static final String RIGHT_PREFIX = "r"; | ||
| private final Session session; | ||
|
|
@@ -286,11 +287,7 @@ public PlanNode visitJoin(JoinNode joinNode, RewriteContext<Set<VariableReferenc | |
| PlanNode rewrittenLeft = context.rewrite(joinNode.getLeft(), context.get()); | ||
| PlanNode rewrittenRight = context.rewrite(joinNode.getRight(), context.get()); | ||
|
|
||
| JoinNodeStatsEstimate joinEstimate = statsProvider.getStats(joinNode).getJoinNodeStatsEstimate(); | ||
| boolean isValidEstimate = !Double.isNaN(joinEstimate.getJoinBuildKeyCount()) && !Double.isNaN(joinEstimate.getNullJoinBuildKeyCount()); | ||
| boolean enabledByCostModel = isValidEstimate && strategy.equals(COST_BASED) && joinEstimate.getNullJoinBuildKeyCount() > NULL_BUILD_KEY_COUNT_THRESHOLD | ||
| && joinEstimate.getNullJoinBuildKeyCount() / joinEstimate.getJoinBuildKeyCount() > getRandomizeOuterJoinNullKeyNullRatioThreshold(session); | ||
|
|
||
| boolean enabledByCostModel = strategy.equals(COST_BASED) && hasNullSkew(statsProvider.getStats(joinNode).getJoinNodeStatsEstimate()); | ||
| List<JoinNode.EquiJoinClause> candidateEquiJoinClauses = joinNode.getCriteria().stream() | ||
| .filter(x -> isSupportedType(x.getLeft()) && isSupportedType(x.getRight())) | ||
| .filter(x -> enabledByCostModel || strategy.equals(ALWAYS) || enabledForJoinKeyFromOuterJoin(context.get(), x)) | ||
|
|
@@ -382,6 +379,16 @@ public PlanNode visitJoin(JoinNode joinNode, RewriteContext<Set<VariableReferenc | |
| return newJoinNode; | ||
| } | ||
|
|
||
| private boolean hasNullSkew(JoinNodeStatsEstimate joinEstimate) | ||
|
||
| { | ||
| boolean isValidEstimate = !Double.isNaN(joinEstimate.getJoinBuildKeyCount()) && !Double.isNaN(joinEstimate.getNullJoinBuildKeyCount()) | ||
| && !Double.isNaN(joinEstimate.getJoinProbeKeyCount()) && !Double.isNaN(joinEstimate.getNullJoinProbeKeyCount()); | ||
| return isValidEstimate && ((joinEstimate.getNullJoinBuildKeyCount() > NULL_BUILD_KEY_COUNT_THRESHOLD | ||
| && joinEstimate.getNullJoinBuildKeyCount() / joinEstimate.getJoinBuildKeyCount() > getRandomizeOuterJoinNullKeyNullRatioThreshold(session)) | ||
| || (joinEstimate.getNullJoinProbeKeyCount() > NULL_PROBE_KEY_COUNT_THRESHOLD | ||
| && joinEstimate.getNullJoinProbeKeyCount() / joinEstimate.getJoinProbeKeyCount() > getRandomizeOuterJoinNullKeyNullRatioThreshold(session))); | ||
| } | ||
|
|
||
| private RowExpression randomizeJoinKey(RowExpression keyExpression, String prefix) | ||
| { | ||
| int partitionCount = getHashPartitionCount(session); | ||
|
|
||
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.
Piggyback the count here, without adding overhead in counting.