Search in sources :

Example 26 with PlanNode

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

the class SubQueryPreProcessor method addSubQuery.

private static void addSubQuery(PlanNode node, ItemSubQuery subQuery, BoolPtr childTransform) {
    node.getSubQueries().add(subQuery);
    PlanNode subNode = findComparisonsSubQueryToJoinNode(subQuery.getPlanNode(), childTransform);
    subQuery.setPlanNode(subNode);
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode)

Example 27 with PlanNode

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

the class SubQueryPreProcessor method findComparisonsSubQueryToJoinNode.

/**
 * http://dev.mysql.com/doc/refman/5.0/en/comparisons-using-subqueries.html
 */
private static PlanNode findComparisonsSubQueryToJoinNode(PlanNode qtn, BoolPtr childTransform) {
    for (int i = 0; i < qtn.getChildren().size(); i++) {
        PlanNode child = qtn.getChildren().get(i);
        qtn.getChildren().set(i, findComparisonsSubQueryToJoinNode(child, childTransform));
    }
    for (Item itemSelect : qtn.getColumnsSelected()) {
        if (itemSelect instanceof ItemScalarSubQuery) {
            ItemScalarSubQuery scalarSubQuery = (ItemScalarSubQuery) itemSelect;
            findComparisonsSubQueryToJoinNode(scalarSubQuery.getPlanNode(), childTransform);
        }
    }
    // having contains sub query
    buildSubQuery(qtn, new SubQueryFilter(), qtn.getHavingFilter(), false, childTransform);
    SubQueryFilter find = new SubQueryFilter();
    find.query = qtn;
    find.filter = null;
    Item where = qtn.getWhereFilter();
    SubQueryFilter result = buildSubQuery(qtn, find, where, false, childTransform);
    if (result != find) {
        // that means where filter only contains sub query,just replace it
        result.query.query(result.filter);
        qtn.query(null);
        // change result.filter and rebuild
        result.query.setUpFields();
        childTransform.set(true);
        return result.query;
    } else {
        if (childTransform.get()) {
            qtn.setUpFields();
        }
        return qtn;
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) ItemScalarSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemScalarSubQuery)

Example 28 with PlanNode

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

the class SubQueryProcessor method tryTransformerQuery.

/**
 * find query node in qtn ,change to other 3 type node
 */
private static PlanNode tryTransformerQuery(PlanNode qtn, BoolPtr boolptr) {
    boolean childMerged = false;
    for (int index = 0; index < qtn.getChildren().size(); index++) {
        PlanNode child = qtn.getChildren().get(index);
        BoolPtr boolPtr = new BoolPtr(false);
        PlanNode newChild = tryTransformerQuery(child, boolPtr);
        if (boolPtr.get())
            childMerged = true;
        qtn.getChildren().set(index, newChild);
    }
    if (childMerged)
        qtn.setUpFields();
    if (qtn.type() == PlanNodeType.QUERY) {
        qtn = transformerQuery((QueryNode) qtn, boolptr);
    }
    return qtn;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) QueryNode(com.actiontech.dble.plan.node.QueryNode) BoolPtr(com.actiontech.dble.plan.common.ptr.BoolPtr)

Example 29 with PlanNode

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

the class SubQueryProcessor method transformerQuery.

/**
 * transformerQuery
 */
private static PlanNode transformerQuery(QueryNode query, BoolPtr boolptr) {
    boolean canBeMerged = canBeMerged(query.getChild());
    if (canBeMerged) {
        // merge view node's property to view's child
        PlanNode newNode = mergeNode(query, query.getChild());
        boolptr.set(true);
        return newNode;
    } else {
        return query;
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode)

Example 30 with PlanNode

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

the class PlanUtil method findColumnInTableLeaf.

/**
 * check obj is the column of an real tablenode ,if obj is not Column Type return null
 * <the column to be found must be  table's parent's column>
 *
 * @param column column
 * @param node node
 * @return the target table node and the column
 */
public static Pair<TableNode, ItemField> findColumnInTableLeaf(ItemField column, PlanNode node) {
    // union return
    if (node.type() == PlanNodeType.MERGE)
        return null;
    NamedField tmpField = new NamedField(column.getTableName(), column.getItemName(), null);
    NamedField coutField = node.getInnerFields().get(tmpField);
    if (coutField == null)
        return null;
    else if (node.type() == PlanNodeType.TABLE) {
        return new Pair<>((TableNode) node, column);
    } else {
        PlanNode referNode = column.getReferTables().iterator().next();
        Item cSel = referNode.getOuterFields().get(coutField);
        if (cSel instanceof ItemField) {
            return findColumnInTableLeaf((ItemField) cSel, referNode);
        } else {
            return null;
        }
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) NamedField(com.actiontech.dble.plan.NamedField) TableNode(com.actiontech.dble.plan.node.TableNode)

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