use of com.actiontech.dble.plan.node.JoinNode in project dble by actiontech.
the class ERJoinChooser method innerJoinOptimizer.
/* ------------------- left join optimizer end -------------------- */
/**
* inner join's ER, rebuild inner joi's unit
*
* @return
*/
private JoinNode innerJoinOptimizer() {
initInnerJoinUnits(jn);
if (joinUnits.size() == 1) {
return jn;
}
visitJoinOns(jn);
initJoinKeyInfo();
while (trySelListIndex < selLists.size()) {
List<JoinKeyInfo> selList = selLists.get(trySelListIndex);
JoinNode erJoinNode = tryMakeERJoin(selList);
if (erJoinNode == null) {
trySelListIndex++;
} else {
// re scanning
this.makedERJnList.add(erJoinNode);
}
}
if (makedERJnList.isEmpty())
// no er join
return jn;
List<PlanNode> others = new ArrayList<>();
// make makedErJnList at the beginning,join with ER
others.addAll(makedERJnList);
others.addAll(joinUnits);
for (int i = 0; i < others.size(); i++) {
// make up the unit which cna;t optimized and global table
PlanNode tnewOther = others.get(i);
PlanNode newT0 = joinWithGlobal(tnewOther, globals);
others.set(i, newT0);
}
// only others and globals may have node and have been tried to ER JOIN
if (globals.size() > 0) {
PlanNode globalJoin = makeJoinNode(globals);
others.add(globalJoin);
}
// others' node is the join units which can not optimize, just merge them
JoinNode ret = (JoinNode) makeJoinNode(others);
ret.setOrderBys(jn.getOrderBys());
ret.setGroupBys(jn.getGroupBys());
ret.select(jn.getColumnsSelected());
ret.setLimitFrom(jn.getLimitFrom());
ret.setLimitTo(jn.getLimitTo());
ret.setOtherJoinOnFilter(FilterUtils.and(jn.getOtherJoinOnFilter(), FilterUtils.and(otherJoinOns)));
Item unFoundSelFilter = makeRestFilter();
if (unFoundSelFilter != null)
ret.setOtherJoinOnFilter(FilterUtils.and(ret.getOtherJoinOnFilter(), unFoundSelFilter));
// and the origin where and the remain condition in selLists
ret.having(jn.getHavingFilter());
ret.setWhereFilter(jn.getWhereFilter());
ret.setAlias(jn.getAlias());
ret.setSubQuery(jn.isSubQuery());
ret.setSql(jn.getSql());
ret.setUpFields();
return ret;
}
Aggregations