Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Nov 30, 2023
1 parent a2aa64b commit d9ff0fc
Showing 1 changed file with 4 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*/
public class JoinEstimation {
private static double DEFAULT_ANTI_JOIN_SELECTIVITY_COEFFICIENT = 0.3;

private static double UNKNOWN_COL_STATS_FILTER_SEL_LOWER_BOUND = 0.5;
private static EqualPredicate normalizeHashJoinCondition(EqualPredicate equal, Statistics leftStats,
Statistics rightStats) {
boolean changeOrder = equal.left().getInputSlots().stream()
Expand Down Expand Up @@ -170,33 +170,7 @@ private static Statistics estimateNestLoopJoin(Statistics leftStats, Statistics
.build();
}

private static double computeSelectivityForInnerJoinWhenColStatsUnknown(
Statistics leftStats, Statistics rightStats, Join join) {
double sel = 1.0;
for (Expression cond : join.getHashJoinConjuncts()) {
if (cond instanceof EqualTo) {
EqualTo equal = (EqualTo) cond;
if (equal.left() instanceof Slot && equal.right() instanceof Slot) {
ColumnStatistic leftColStats = leftStats.findColumnStatistics(equal.left());
ColumnStatistic rightColStats = rightStats.findColumnStatistics(equal.right());
if (leftColStats == null) {
leftColStats = leftStats.findColumnStatistics(equal.right());
rightColStats = rightStats.findColumnStatistics(equal.left());
}
if (leftColStats != null && rightColStats != null) {
double leftSel = Math.min(leftColStats.count / leftStats.getRowCount(), 1.0);
leftSel = Math.max(leftSel, 0.5);
double rightSel = Math.min(rightColStats.count / rightStats.getRowCount(), 1.0);
rightSel = Math.max(rightSel, 0.5);
sel = Math.min(sel, Math.min(leftSel, rightSel));
}
}
}
}
return sel;
}

private static double computeSelectivityForSemiOrAntiJoinWhenColStatsUnknown(Statistics buildStats, Join join) {
private static double computeSelectivityForBuildSideWhenColStatsUnknown(Statistics buildStats, Join join) {
double sel = 1.0;
for (Expression cond : join.getHashJoinConjuncts()) {
if (cond instanceof EqualTo) {
Expand All @@ -208,7 +182,7 @@ private static double computeSelectivityForSemiOrAntiJoinWhenColStatsUnknown(Sta
}
if (buildColStats != null) {
double buildSel = Math.min(buildStats.getRowCount() / buildColStats.count, 1.0);
buildSel = Math.max(buildSel, 0.5);
buildSel = Math.max(buildSel, UNKNOWN_COL_STATS_FILTER_SEL_LOWER_BOUND);
sel = Math.min(sel, buildSel);
}
}
Expand All @@ -220,8 +194,6 @@ private static double computeSelectivityForSemiOrAntiJoinWhenColStatsUnknown(Sta
private static Statistics estimateInnerJoin(Statistics leftStats, Statistics rightStats, Join join) {
if (hashJoinConditionContainsUnknownColumnStats(leftStats, rightStats, join)) {
double rowCount = Math.max(leftStats.getRowCount(), rightStats.getRowCount());
double sel = computeSelectivityForInnerJoinWhenColStatsUnknown(leftStats, rightStats, join);
rowCount = rowCount * sel;
rowCount = Math.max(1, rowCount);
return new StatisticsBuilder()
.setRowCount(rowCount)
Expand Down Expand Up @@ -295,7 +267,7 @@ private static double estimateSemiOrAntiRowCountBySlotsEqual(Statistics leftStat

private static Statistics estimateSemiOrAnti(Statistics leftStats, Statistics rightStats, Join join) {
if (hashJoinConditionContainsUnknownColumnStats(leftStats, rightStats, join)) {
double sel = computeSelectivityForSemiOrAntiJoinWhenColStatsUnknown(rightStats, join);
double sel = computeSelectivityForBuildSideWhenColStatsUnknown(rightStats, join);
if (join.getJoinType().isLeftSemiOrAntiJoin()) {
return new StatisticsBuilder().setRowCount(leftStats.getRowCount() * sel)
.putColumnStatistics(leftStats.columnStatistics())
Expand Down

0 comments on commit d9ff0fc

Please sign in to comment.