Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ private static Plan transform(MatchingContext<LogicalJoin<Plan, Plan>> ctx) {
LogicalJoin<Plan, Plan> join = ctx.root;
Expression skewExpr = null;
List<Expression> hotValues = new ArrayList<>();
if (join.getHashJoinConjuncts().size() != 1) {
boolean allowMultiKey =
ConnectContext.get().getSessionVariable().isEnableSkewJoinMultiKey();
if (!allowMultiKey && join.getHashJoinConjuncts().size() != 1) {
return null;
}
AbstractPlan left = (AbstractPlan) join.left();
Expand All @@ -82,35 +84,37 @@ private static Plan transform(MatchingContext<LogicalJoin<Plan, Plan>> ctx) {
right.accept(derive, new DeriveContext());
}

EqualPredicate equal = (EqualPredicate) join.getHashJoinConjuncts().get(0);
if (join.left().getOutputSet().contains(equal.right())) {
equal = equal.commute();
}

if (join.getJoinType().isInnerJoin() || join.getJoinType().isLeftOuterJoin()) {
Expression leftEqHand = equal.child(0);
if (left.getStats().findColumnStatistics(leftEqHand) != null) {
ColumnStatistic leftColStats = left.getStats().findColumnStatistics(leftEqHand);
Map<Literal, Float> filtered = StatisticsUtil.getHotValuesWithOriginalThreshold(
leftColStats.getHotValues(), leftColStats.ndv);
if (filtered != null) {
skewExpr = leftEqHand;
hotValues.addAll(filtered.keySet());
}
for (Expression conjunct : join.getHashJoinConjuncts()) {
EqualPredicate equal = (EqualPredicate) conjunct;
if (join.left().getOutputSet().contains(equal.right())) {
equal = equal.commute();
}
} else if (join.getJoinType().isRightOuterJoin()) {
Expression rightEqHand = equal.child(1);
if (right.getStats().findColumnStatistics(rightEqHand) != null) {
ColumnStatistic rightColStats = right.getStats().findColumnStatistics(rightEqHand);
Map<Literal, Float> filtered = StatisticsUtil.getHotValuesWithOriginalThreshold(
rightColStats.getHotValues(), rightColStats.ndv);
if (filtered != null) {
skewExpr = rightEqHand;
hotValues.addAll(filtered.keySet());
Map<Literal, Float> filtered = null;
Expression sideExpr = null;
if (join.getJoinType().isInnerJoin() || join.getJoinType().isLeftOuterJoin()) {
Expression leftEqHand = equal.child(0);
if (left.getStats().findColumnStatistics(leftEqHand) != null) {
ColumnStatistic leftColStats = left.getStats().findColumnStatistics(leftEqHand);
filtered = StatisticsUtil.getHotValuesWithOriginalThreshold(
leftColStats.getHotValues(), leftColStats.ndv);
sideExpr = leftEqHand;
}
} else if (join.getJoinType().isRightOuterJoin()) {
Expression rightEqHand = equal.child(1);
if (right.getStats().findColumnStatistics(rightEqHand) != null) {
ColumnStatistic rightColStats = right.getStats().findColumnStatistics(rightEqHand);
filtered = StatisticsUtil.getHotValuesWithOriginalThreshold(
rightColStats.getHotValues(), rightColStats.ndv);
sideExpr = rightEqHand;
}
} else {
return null;
}
if (filtered != null && !filtered.isEmpty()) {
skewExpr = sideExpr;
hotValues.addAll(filtered.keySet());
break;
}
} else {
return null;
}
if (skewExpr == null || hotValues.isEmpty()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ public String toString() {
// turn off all automatic join reorder algorithms
public static final String DISABLE_JOIN_REORDER = "disable_join_reorder";

// Allow SkewJoin auto-salt to trigger on joins with more than one hash key.
public static final String ENABLE_SKEW_JOIN_MULTI_KEY = "enable_skew_join_multi_key";

public static final String MAX_JOIN_NUMBER_OF_REORDER = "max_join_number_of_reorder";

public static final String ENABLE_NEREIDS_DML = "enable_nereids_dml";
Expand Down Expand Up @@ -1949,6 +1952,9 @@ public void setCboNetWeight(double cboNetWeight) {
@VarAttrDef.VarAttr(name = DISABLE_JOIN_REORDER)
private boolean disableJoinReorder = false;

@VarAttrDef.VarAttr(name = ENABLE_SKEW_JOIN_MULTI_KEY, needForward = true)
private boolean enableSkewJoinMultiKey = true;

@VarAttrDef.VarAttr(name = MAX_JOIN_NUMBER_OF_REORDER)
private int maxJoinNumberOfReorder = 63;

Expand Down Expand Up @@ -5017,6 +5023,14 @@ public boolean isDisableJoinReorder() {
return disableJoinReorder;
}

public boolean isEnableSkewJoinMultiKey() {
return enableSkewJoinMultiKey;
}

public void setEnableSkewJoinMultiKey(boolean enable) {
this.enableSkewJoinMultiKey = enable;
}

public boolean isEnableBushyTree() {
return enableBushyTree;
}
Expand Down
Loading