Search in sources :

Example 21 with JoinNode

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;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) JoinNode(com.actiontech.dble.plan.node.JoinNode) ArrayList(java.util.ArrayList)

Aggregations

JoinNode (com.actiontech.dble.plan.node.JoinNode)21 PlanNode (com.actiontech.dble.plan.node.PlanNode)16 Item (com.actiontech.dble.plan.common.item.Item)6 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)5 ArrayList (java.util.ArrayList)4 ItemField (com.actiontech.dble.plan.common.item.ItemField)3 QueryNode (com.actiontech.dble.plan.node.QueryNode)3 ERTable (com.actiontech.dble.config.model.ERTable)2 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)2 TableNode (com.actiontech.dble.plan.node.TableNode)2 LinkedList (java.util.LinkedList)2 NamedField (com.actiontech.dble.plan.NamedField)1 Order (com.actiontech.dble.plan.Order)1 ItemSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemSubQuery)1 MergeNode (com.actiontech.dble.plan.node.MergeNode)1 ERJoinChooser (com.actiontech.dble.plan.optimizer.ERJoinChooser)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 List (java.util.List)1