Search in sources :

Example 36 with PlanNode

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

the class MergeHavingFilter method optimize.

/**
 * merge having to where if it can be merged
 *
 * @param qtn
 */
public static void optimize(PlanNode qtn) {
    if (qtn.getHavingFilter() != null) {
        List<Item> subFilters = FilterUtils.splitFilter(qtn.getHavingFilter());
        List<Item> canMergeSubs = new ArrayList<>();
        for (Item subFilter : subFilters) {
            if (!subFilter.isWithSumFunc()) {
                canMergeSubs.add(subFilter);
            }
        }
        subFilters.removeAll(canMergeSubs);
        qtn.having(FilterUtils.and(subFilters));
        qtn.setWhereFilter(FilterUtils.and(qtn.getWhereFilter(), FilterUtils.and(canMergeSubs)));
    }
    for (PlanNode child : qtn.getChildren()) optimize(child);
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) ArrayList(java.util.ArrayList)

Example 37 with PlanNode

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

the class MyOptimizer method updateReferedTableNodes.

private static List<TableNode> updateReferedTableNodes(PlanNode node) {
    List<TableNode> subTables = new ArrayList<>();
    for (PlanNode childNode : node.getChildren()) {
        List<TableNode> childSubTables = updateReferedTableNodes(childNode);
        node.getReferedTableNodes().addAll(childSubTables);
        subTables.addAll(childSubTables);
    }
    for (ItemSubQuery subQuery : node.getSubQueries()) {
        List<TableNode> childSubTables = subQuery.getPlanNode().getReferedTableNodes();
        node.getReferedTableNodes().addAll(childSubTables);
        subTables.addAll(childSubTables);
    }
    return subTables;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) TableNode(com.actiontech.dble.plan.node.TableNode) ArrayList(java.util.ArrayList) ItemSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemSubQuery)

Example 38 with PlanNode

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

the class ERJoinChooser method makeJoinNode.

/**
 * just makeJoinNode according with wishes
 *
 * @param units
 * @return
 */
private PlanNode makeJoinNode(List<PlanNode> units) {
    PlanNode ret = units.get(0);
    for (int i = 1; i < units.size(); i++) {
        PlanNode tni = units.get(i);
        JoinNode joinNode = new JoinNode(ret, tni);
        List<ItemFuncEqual> joinFilter = makeJoinFilter(joinNode, ret, tni, true);
        joinNode.setJoinFilter(joinFilter);
        ret = joinNode;
    }
    return ret;
}
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 39 with PlanNode

use of com.actiontech.dble.plan.node.PlanNode 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)

Example 40 with PlanNode

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

the class ERJoinChooser method leftJoinOptimizer.

/* ------------------- left join optimizer start -------------------- */
/**
 * left join's ER is different from inner join's
 * ex:t1,t2 ,if t1 left join t2 on
 * t1.id=t2.id can be pushed
 * < we cna't change left join's structure>
 *
 * @return
 */
private JoinNode leftJoinOptimizer() {
    PlanNode left = jn.getLeftNode();
    PlanNode right = jn.getRightNode();
    if (left.type() == PlanNode.PlanNodeType.JOIN) {
        left = JoinERProcessor.optimize(left);
        jn.setLeftNode(left);
    }
    if (right.type() == PlanNode.PlanNodeType.JOIN) {
        right = JoinERProcessor.optimize(right);
        jn.setRightNode(right);
    }
    for (ItemFuncEqual filter : jn.getJoinFilter()) {
        ERTable leftER = getLeftOutJoinChildER(jn, left, filter.arguments().get(0));
        ERTable rightER = getLeftOutJoinChildER(jn, right, filter.arguments().get(1));
        if (isErRelation(leftER, rightER)) {
            jn.getERkeys().add(leftER);
        }
    }
    return jn;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual) ERTable(com.actiontech.dble.config.model.ERTable)

Aggregations

PlanNode (com.actiontech.dble.plan.node.PlanNode)50 JoinNode (com.actiontech.dble.plan.node.JoinNode)16 Item (com.actiontech.dble.plan.common.item.Item)14 ArrayList (java.util.ArrayList)10 QueryNode (com.actiontech.dble.plan.node.QueryNode)8 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)6 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)5 MySQLPlanNodeVisitor (com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)5 ItemSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemSubQuery)4 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)4 DMLResponseHandler (com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler)3 NamedField (com.actiontech.dble.plan.NamedField)3 ErrorPacket (com.actiontech.dble.net.mysql.ErrorPacket)2 Order (com.actiontech.dble.plan.Order)2 TableNode (com.actiontech.dble.plan.node.TableNode)2 HashSet (java.util.HashSet)2 BaseHandlerBuilder (com.actiontech.dble.backend.mysql.nio.handler.builder.BaseHandlerBuilder)1 HandlerBuilder (com.actiontech.dble.backend.mysql.nio.handler.builder.HandlerBuilder)1 TempTableHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.TempTableHandler)1 CallBackHandler (com.actiontech.dble.backend.mysql.nio.handler.util.CallBackHandler)1