Search in sources :

Example 11 with JoinNode

use of com.actiontech.dble.plan.node.JoinNode in project dble by actiontech.

the class ERJoinChooser method makeERJoin.

// generate er join node ,remove jk of rKeyIndexs in selListIndex,replace the other selList's tn
private JoinNode makeERJoin(List<JoinKeyInfo> erKeys) {
    PlanNode t0 = erKeys.get(0).tn;
    PlanNode t1 = erKeys.get(1).tn;
    JoinNode joinNode = new JoinNode(t0, t1);
    List<ItemFuncEqual> joinFilter = makeJoinFilter(joinNode, t0, t1, true);
    joinNode.setJoinFilter(joinFilter);
    for (int index = 2; index < erKeys.size(); index++) {
        t0 = joinNode;
        t1 = erKeys.get(index).tn;
        joinNode = new JoinNode(t0, t1);
        joinFilter = makeJoinFilter(joinNode, t0, t1, true);
        joinNode.setJoinFilter(joinFilter);
    }
    for (JoinKeyInfo jki : erKeys) {
        // remove join units
        for (int index = joinUnits.size() - 1; index > -1; index--) {
            PlanNode tn = joinUnits.get(index);
            if (tn == jki.tn)
                joinUnits.remove(index);
        }
    }
    return joinNode;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) JoinNode(com.actiontech.dble.plan.node.JoinNode) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)

Example 12 with JoinNode

use of com.actiontech.dble.plan.node.JoinNode in project dble by actiontech.

the class ERJoinChooser method visitJoinOns.

/**
 * visitJoinOns
 *
 * @param joinNode
 */
private void visitJoinOns(JoinNode joinNode) {
    for (PlanNode unit : joinUnits) {
        // is unit
        if (unit == joinNode) {
            return;
        }
    }
    for (ItemFuncEqual filter : joinNode.getJoinFilter()) {
        addJoinFilter(filter);
    }
    for (PlanNode child : joinNode.getChildren()) {
        if ((!isUnit(child)) && (child.type().equals(PlanNode.PlanNodeType.JOIN))) {
            // a join b on a.id=b.id and a.id+b.id=10 join c on
            // a.id=c.id,push up a.id+b.id
            JoinNode jnChild = (JoinNode) child;
            if (jnChild.getOtherJoinOnFilter() != null)
                otherJoinOns.add(jnChild.getOtherJoinOnFilter());
            visitJoinOns((JoinNode) child);
        }
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) JoinNode(com.actiontech.dble.plan.node.JoinNode) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)

Example 13 with JoinNode

use of com.actiontech.dble.plan.node.JoinNode in project dble by actiontech.

the class FilterJoinColumnPusher method pushJoinNodeFilter.

private static PlanNode pushJoinNodeFilter(PlanNode qtn, List<Item> dnfNodeToPush) {
    JoinNode jn = (JoinNode) qtn;
    PlanUtil.findJoinKeysAndRemoveIt(dnfNodeToPush, jn);
    if (dnfNodeToPush.isEmpty()) {
        return qtn;
    }
    // filters which can not push down
    List<Item> dnfNodeToCurrent = new LinkedList<>();
    List<Item> dnfNodetoPushToLeft = new LinkedList<>();
    List<Item> dnfNodetoPushToRight = new LinkedList<>();
    for (Item filter : dnfNodeToPush) {
        if (PlanUtil.canPush(filter, jn.getLeftNode(), jn)) {
            dnfNodetoPushToLeft.add(filter);
        } else if (PlanUtil.canPush(filter, jn.getRightNode(), jn)) {
            dnfNodetoPushToRight.add(filter);
        } else {
            dnfNodeToCurrent.add(filter);
        }
    }
    // if can not push down,merge to current where
    Item node = FilterUtils.and(dnfNodeToCurrent);
    if (node != null) {
        qtn.query(FilterUtils.and(qtn.getWhereFilter(), node));
    }
    if (jn.isInnerJoin()) {
        refreshPdFilters(jn, dnfNodetoPushToLeft);
        refreshPdFilters(jn, dnfNodetoPushToRight);
        pushFilter(jn.getLeftNode(), dnfNodetoPushToLeft);
        pushFilter(((JoinNode) qtn).getRightNode(), dnfNodetoPushToRight);
    } else if (jn.isLeftOuterJoin()) {
        refreshPdFilters(jn, dnfNodetoPushToLeft);
        pushFilter(jn.getLeftNode(), dnfNodetoPushToLeft);
        if (!dnfNodeToPush.isEmpty()) {
            // the parent's filter,don't push down
            jn.query(FilterUtils.and(dnfNodetoPushToRight));
        }
    } else if (jn.isRightOuterJoin()) {
        refreshPdFilters(jn, dnfNodetoPushToRight);
        pushFilter(((JoinNode) qtn).getRightNode(), dnfNodetoPushToRight);
        if (!dnfNodeToPush.isEmpty()) {
            // the parent's filter,don't push down
            jn.query(FilterUtils.and(dnfNodetoPushToLeft));
        }
    } else {
        if (!dnfNodeToPush.isEmpty()) {
            jn.query(FilterUtils.and(dnfNodeToPush));
        }
    }
    return qtn;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) JoinNode(com.actiontech.dble.plan.node.JoinNode) LinkedList(java.util.LinkedList)

Example 14 with JoinNode

use of com.actiontech.dble.plan.node.JoinNode in project dble by actiontech.

the class FilterPreProcessor method preProcess.

private static PlanNode preProcess(PlanNode qtn) {
    qtn.having(processFilter(qtn.getHavingFilter()));
    qtn.query(processFilter(qtn.getWhereFilter()));
    if (qtn instanceof JoinNode) {
        JoinNode jn = (JoinNode) qtn;
        for (int i = 0; i < ((JoinNode) qtn).getJoinFilter().size(); i++) {
            processFilter(jn.getJoinFilter().get(i));
        }
        jn.setOtherJoinOnFilter(processFilter(jn.getOtherJoinOnFilter()));
    }
    for (PlanNode child : qtn.getChildren()) {
        preProcess(child);
    }
    return qtn;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) JoinNode(com.actiontech.dble.plan.node.JoinNode)

Example 15 with JoinNode

use of com.actiontech.dble.plan.node.JoinNode in project dble by actiontech.

the class FilterPusher method mergeJoinOnFilter.

/**
 * merge inner joi's otheron to where if we can
 *
 * @param qtn
 * @return
 */
private static void mergeJoinOnFilter(PlanNode qtn) {
    if (PlanUtil.isGlobalOrER(qtn))
        return;
    if (qtn.type().equals(PlanNodeType.JOIN) && ((JoinNode) qtn).isInnerJoin()) {
        JoinNode jn = (JoinNode) qtn;
        Item otherJoinOn = jn.getOtherJoinOnFilter();
        jn.setOtherJoinOnFilter(null);
        jn.query(FilterUtils.and(otherJoinOn, jn.getWhereFilter()));
    }
    for (PlanNode child : qtn.getChildren()) {
        mergeJoinOnFilter(child);
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) JoinNode(com.actiontech.dble.plan.node.JoinNode)

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