Search in sources :

Example 16 with PlanNode

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

the class NonBlockingSession method executeMultiSelect.

private void executeMultiSelect(RouteResultset rrs) {
    SQLSelectStatement ast = (SQLSelectStatement) rrs.getSqlStatement();
    MySQLPlanNodeVisitor visitor = new MySQLPlanNodeVisitor(this.getSource().getSchema(), this.getSource().getCharset().getResultsIndex(), DbleServer.getInstance().getTmManager(), false);
    visitor.visit(ast);
    PlanNode node = visitor.getTableNode();
    if (node.isCorrelatedSubQuery()) {
        throw new MySQLOutPutException(ErrorCode.ER_UNKNOWN_ERROR, "", "Correlated Sub Queries is not supported ");
    }
    node.setSql(rrs.getStatement());
    node.setUpFields();
    PlanUtil.checkTablesPrivilege(source, node, ast);
    node = MyOptimizer.optimize(node);
    if (PlanUtil.containsSubQuery(node)) {
        final PlanNode finalNode = node;
        DbleServer.getInstance().getComplexQueryExecutor().execute(new Runnable() {

            // sub Query build will be blocked, so use ComplexQueryExecutor
            @Override
            public void run() {
                executeMultiResultSet(finalNode);
            }
        });
    } else {
        if (!visitor.isContainSchema()) {
            node.setAst(ast);
        }
        executeMultiResultSet(node);
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySQLPlanNodeVisitor(com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 17 with PlanNode

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

the class ERJoinChooser method joinWithGlobal.

private PlanNode joinWithGlobal(PlanNode t, List<PlanNode> globalList) {
    PlanNode newT = t;
    while (globalList.size() > 0) {
        boolean foundJoin = false;
        for (int i = 0; i < globalList.size(); i++) {
            PlanNode global = globalList.get(i);
            // try join
            JoinNode joinNode = new JoinNode(newT, global);
            List<ItemFuncEqual> jnFilter = makeJoinFilter(joinNode, newT, global, false);
            // @if no join column, then the other is cross join
            if (jnFilter.size() > 0 || selLists.size() == 0) {
                // join
                replaceSelListReferedTn(newT, global, joinNode);
                foundJoin = true;
                joinNode.setJoinFilter(jnFilter);
                globalList.remove(i);
                newT = joinNode;
                break;
            }
        }
        if (// no join can do from t and globals
        !foundJoin)
            break;
    }
    return newT;
}
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 18 with PlanNode

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

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

the class ERJoinChooser method initJoinKeyInfo.

/**
 * init sellis's JoinKeyInfo,JoinKeyInfo only has key selList when just build ,
 * set values for them
 */
private void initJoinKeyInfo() {
    for (List<JoinKeyInfo> selList : selLists) {
        for (JoinKeyInfo jki : selList) {
            for (PlanNode tn : joinUnits) {
                Item tmpSel = nodeHasSelectable(tn, jki.key);
                if (tmpSel != null) {
                    jki.tn = tn;
                    jki.cm = getERKey(tn, tmpSel);
                    break;
                }
            }
        }
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode)

Example 20 with PlanNode

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

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