Skip to content

Commit 76155e3

Browse files
committed
optimize er left join global (#2334)
* optimize er left join global * optimize er left join global * fix checkstyle (cherry picked from commit 2f6b3bf)
1 parent 0f4d5fd commit 76155e3

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

dble_checkstyle_suppression.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
<suppress checks=".*" files="BTraceCostTime.java"/>
2424
<suppress checks="CyclomaticComplexity" files="CreateTableParserImp.java"/>
2525
<suppress checks="CyclomaticComplexity" files="XMLSchemaLoader.java"/>
26-
26+
<suppress checks="CyclomaticComplexity" files="GlobalTableProcessor.java"/>
2727
</suppressions>

src/main/java/com/actiontech/dble/plan/optimizer/ERJoinChooser.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public JoinNode optimize() {
7777
* left join's ER is different from inner join's
7878
* ex:t1,t2 ,if t1 left join t2 on
7979
* t1.id=t2.id can be pushed
80-
* < we cna't change left join's structure>
80+
* < we can't change left join's structure>
8181
*
8282
* @return
8383
*/
@@ -107,6 +107,7 @@ private ERTable getLeftOutJoinChildER(JoinNode joinNode, PlanNode child, Item on
107107
return null;
108108
else if (!PlanUtil.isERNode(child) && child.type() != PlanNode.PlanNodeType.TABLE)
109109
return null;
110+
110111
if (onItem == null || !onItem.type().equals(Item.ItemType.FIELD_ITEM))
111112
return null;
112113
Pair<TableNode, ItemField> joinColumnInfo = PlanUtil.findColumnInTableLeaf((ItemField) onItem, joinNode);
@@ -130,7 +131,7 @@ else if (!PlanUtil.isERNode(child) && child.type() != PlanNode.PlanNodeType.TABL
130131
/* ------------------- left join optimizer end -------------------- */
131132

132133
/**
133-
* inner join's ER, rebuild inner joi's unit
134+
* inner join's ER, rebuild inner join's unit
134135
*
135136
* @return
136137
*/
@@ -390,7 +391,8 @@ private void initInnerJoinUnits(JoinNode node) {
390391
private boolean isUnit(PlanNode node) {
391392
if (isGlobalTree(node))
392393
return true;
393-
else return node.type() != PlanNode.PlanNodeType.JOIN || node.isWithSubQuery() || !((JoinNode) node).isInnerJoin();
394+
else
395+
return node.type() != PlanNode.PlanNodeType.JOIN || node.isWithSubQuery() || !((JoinNode) node).isInnerJoin();
394396
}
395397

396398
/**

src/main/java/com/actiontech/dble/plan/optimizer/GlobalTableProcessor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ private static boolean initGlobalStatus(PlanNode tn) {
4747
if (PlanUtil.isERNode(tn)) {
4848
// treat er join as an un global table
4949
tn.setUnGlobalTableCount(1);
50-
Set<String> newSet = new HashSet<>();
51-
newSet.addAll(tn.getReferedTableNodes().get(0).getNoshardNode());
50+
Set<String> newSet = new HashSet<>(tn.getReferedTableNodes().get(0).getNoshardNode());
5251
tn.setNoshardNode(newSet);
5352
} else {
5453
int unGlobalCount = calcUnGlobalCount(tn);
@@ -76,7 +75,9 @@ private static boolean initGlobalStatus(PlanNode tn) {
7675
if (left.getUnGlobalTableCount() == 0) { // left node is global,left join will not push down
7776
tn.setNoshardNode(null);
7877
status = false;
79-
} else if (left.type() == PlanNode.PlanNodeType.TABLE || PlanUtil.isERNode(left)) {
78+
} else if (left.type() == PlanNode.PlanNodeType.TABLE ||
79+
PlanUtil.isERNode(left) ||
80+
left.getNoshardNode() != null && left.getNoshardNode().size() > 0) {
8081
if (!isGlobalTableBigEnough(jn)) {
8182
tn.setNoshardNode(null);
8283
status = false;

0 commit comments

Comments
 (0)