Skip to content

Commit

Permalink
left zig zag
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Nov 3, 2023
1 parent eb24f51 commit 188001d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ private List<Rule> getExplorationRules() {
.getSessionVariable().isEnableLeftZigZag();
int joinNumBushyTree = context.getCascadesContext().getConnectContext()
.getSessionVariable().getMaxJoinNumBushyTree();
if (isDisableJoinReorder) {
return Collections.emptyList();
} else if (enableLeftZigZag) {
return getRuleSet().getLeftZigZagTreeJoinReorder();
} else if (isDpHyp) {
if (isOtherJoinReorder) {
return getRuleSet().getDPHypReorderRules();
} else {
return Collections.emptyList();
}
} else if (isEnableBushyTree) {
return getRuleSet().getBushyTreeJoinReorder();
} else if (context.getCascadesContext().getStatementContext().getMaxNAryInnerJoin() <= joinNumBushyTree) {
return getRuleSet().getBushyTreeJoinReorder();
} else {
return getRuleSet().getZigZagTreeJoinReorder();
}
if (isDisableJoinReorder) {
return Collections.emptyList();
} else if (enableLeftZigZag) {
return getRuleSet().getLeftZigZagTreeJoinReorder();
} else if (isDpHyp) {
if (isOtherJoinReorder) {
return getRuleSet().getDPHypReorderRules();
} else {
return Collections.emptyList();
}
} else if (isEnableBushyTree) {
return getRuleSet().getBushyTreeJoinReorder();
} else if (context.getCascadesContext().getStatementContext().getMaxNAryInnerJoin() <= joinNumBushyTree) {
return getRuleSet().getBushyTreeJoinReorder();
} else {
return getRuleSet().getZigZagTreeJoinReorder();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ public class RuleSet {
.build();

public static final List<Rule> LEFT_ZIG_ZAG_TREE_JOIN_REORDER = planRuleFactories()
.add(JoinCommute.LEFT_ZIG_ZAG)
.add(InnerJoinLAsscom.INSTANCE)
.add(InnerJoinLAsscomProject.INSTANCE)
.build();
.add(JoinCommute.LEFT_ZIG_ZAG)
.add(InnerJoinLAsscom.LEFT_ZIG_ZAG)
.add(InnerJoinLAsscomProject.LEFT_ZIG_ZAG)
.build();

public static final List<Rule> ZIG_ZAG_TREE_JOIN_REORDER = planRuleFactories()
.add(JoinCommute.ZIG_ZAG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
* Rule for change inner join LAsscom (associative and commutive).
*/
public class InnerJoinLAsscom extends OneExplorationRuleFactory {
public static final InnerJoinLAsscom INSTANCE = new InnerJoinLAsscom();
public static final InnerJoinLAsscom INSTANCE = new InnerJoinLAsscom(false);
public static final InnerJoinLAsscom LEFT_ZIG_ZAG = new InnerJoinLAsscom(true);
private boolean leftZigZag = false;

public InnerJoinLAsscom(boolean leftZigZag) {
this.leftZigZag = leftZigZag;
}

/*
* topJoin newTopJoin
Expand All @@ -48,7 +54,7 @@ public class InnerJoinLAsscom extends OneExplorationRuleFactory {
@Override
public Rule build() {
return innerLogicalJoin(innerLogicalJoin(), group())
.when(topJoin -> checkReorder(topJoin, topJoin.left()))
.when(topJoin -> checkReorder(topJoin, topJoin.left(), leftZigZag))
.whenNot(join -> join.hasJoinHint() || join.left().hasJoinHint())
.whenNot(join -> join.isMarkJoin() || join.left().isMarkJoin())
.then(topJoin -> {
Expand Down Expand Up @@ -85,13 +91,22 @@ public Rule build() {
}).toRule(RuleType.LOGICAL_INNER_JOIN_LASSCOM);
}

/**
* trigger rule condition
*/
public static boolean checkReorder(LogicalJoin<? extends Plan, GroupPlan> topJoin,
LogicalJoin<GroupPlan, GroupPlan> bottomJoin) {
double bRows = bottomJoin.right().getGroup().getStatistics().getRowCount();
double cRows = topJoin.right().getGroup().getStatistics().getRowCount();
return bRows < cRows && !bottomJoin.getJoinReorderContext().hasCommuteZigZag()
&& !topJoin.getJoinReorderContext().hasLAsscom()
&& (!bottomJoin.isMarkJoin() && !topJoin.isMarkJoin());
LogicalJoin<GroupPlan, GroupPlan> bottomJoin, boolean leftZigZag) {
if (leftZigZag) {
double bRows = bottomJoin.right().getGroup().getStatistics().getRowCount();
double cRows = topJoin.right().getGroup().getStatistics().getRowCount();
return bRows < cRows && !bottomJoin.getJoinReorderContext().hasCommuteZigZag()
&& !topJoin.getJoinReorderContext().hasLAsscom()
&& (!bottomJoin.isMarkJoin() && !topJoin.isMarkJoin());
} else {
return !bottomJoin.getJoinReorderContext().hasCommuteZigZag()
&& !topJoin.getJoinReorderContext().hasLAsscom()
&& (!bottomJoin.isMarkJoin() && !topJoin.isMarkJoin());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@
* Rule for change inner join LAsscom (associative and commutive).
*/
public class InnerJoinLAsscomProject extends OneExplorationRuleFactory {
public static final InnerJoinLAsscomProject INSTANCE = new InnerJoinLAsscomProject();
public static final InnerJoinLAsscomProject INSTANCE = new InnerJoinLAsscomProject(false);
public static final InnerJoinLAsscomProject LEFT_ZIG_ZAG = new InnerJoinLAsscomProject(true);
private final boolean leftZigZag;

public InnerJoinLAsscomProject(boolean leftZigZag) {
this.leftZigZag = leftZigZag;
}
/*
* topJoin newTopJoin
* / \ / \
Expand All @@ -51,10 +56,11 @@ public class InnerJoinLAsscomProject extends OneExplorationRuleFactory {
* / \ / \
* A B A C
*/

@Override
public Rule build() {
return innerLogicalJoin(logicalProject(innerLogicalJoin()), group())
.when(topJoin -> InnerJoinLAsscom.checkReorder(topJoin, topJoin.left().child()))
.when(topJoin -> InnerJoinLAsscom.checkReorder(topJoin, topJoin.left().child(), leftZigZag))
.whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
.whenNot(join -> join.isMarkJoin() || join.left().child().isMarkJoin())
.when(join -> join.left().isAllSlots())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static boolean check(SwapType swapType, LogicalJoin<GroupPlan, GroupPlan>
}

if (swapType == SwapType.LEFT_ZIG_ZAG) {
double leftRows= join.left().getGroup().getStatistics().getRowCount();
double leftRows = join.left().getGroup().getStatistics().getRowCount();
double rightRows = join.right().getGroup().getStatistics().getRowCount();
return leftRows < rightRows && isZigZagJoin(join);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class SemiJoinSemiJoinTransposeProject extends OneExplorationRuleFactory
public Rule build() {
return logicalJoin(logicalProject(logicalJoin()), group())
.when(this::typeChecker)
.when(topSemi -> InnerJoinLAsscom.checkReorder(topSemi, topSemi.left().child()))
.when(topSemi -> InnerJoinLAsscom.checkReorder(topSemi, topSemi.left().child(), false))
.whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
.whenNot(join -> join.isMarkJoin() || join.left().child().isMarkJoin())
.when(join -> join.left().isAllSlots())
Expand Down

0 comments on commit 188001d

Please sign in to comment.