Search in sources :

Example 16 with JoinNode

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

the class JoinERProcessor method optimize.

public static PlanNode optimize(PlanNode qtn) {
    if (qtn instanceof JoinNode) {
        qtn = new ERJoinChooser((JoinNode) qtn).optimize();
    } else {
        for (int i = 0; i < qtn.getChildren().size(); i++) {
            PlanNode sub = qtn.getChildren().get(i);
            qtn.getChildren().set(i, optimize(sub));
        }
    }
    return qtn;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) JoinNode(com.actiontech.dble.plan.node.JoinNode)

Example 17 with JoinNode

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

the class JoinStrategyProcessor method optimize.

public static PlanNode optimize(PlanNode qtn) {
    if (PlanUtil.isGlobalOrER(qtn))
        return qtn;
    if (qtn.type() == PlanNode.PlanNodeType.JOIN) {
        JoinNode jn = (JoinNode) qtn;
        if (jn.getLeftNode().type() == PlanNode.PlanNodeType.TABLE && jn.getRightNode().type() == PlanNode.PlanNodeType.TABLE) {
            JoinStrategyChooser chooser = new JoinStrategyChooser((JoinNode) qtn);
            chooser.tryNestLoop();
            return qtn;
        }
    }
    for (PlanNode child : qtn.getChildren()) optimize(child);
    return qtn;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) JoinNode(com.actiontech.dble.plan.node.JoinNode)

Example 18 with JoinNode

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

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

the class ERJoinChooser method getLeftOutJoinChildER.

private ERTable getLeftOutJoinChildER(JoinNode joinNode, PlanNode child, Item onItem) {
    if (PlanUtil.existAggregate(child))
        return null;
    else if (!PlanUtil.isERNode(child) && child.type() != PlanNode.PlanNodeType.TABLE)
        return null;
    if (onItem == null || !onItem.type().equals(Item.ItemType.FIELD_ITEM))
        return null;
    Pair<TableNode, ItemField> joinColumnInfo = PlanUtil.findColumnInTableLeaf((ItemField) onItem, joinNode);
    if (joinColumnInfo == null)
        return null;
    TableNode tn = joinColumnInfo.getKey();
    ItemField col = joinColumnInfo.getValue();
    ERTable erKey = new ERTable(tn.getSchema(), tn.getPureName(), col.getItemName());
    if (child.type() == PlanNode.PlanNodeType.TABLE) {
        return erKey;
    } else {
        // joinnode
        List<ERTable> erKeys = ((JoinNode) child).getERkeys();
        for (ERTable cerKey : erKeys) {
            if (isErRelation(erKey, cerKey))
                return erKey;
        }
        return null;
    }
}
Also used : JoinNode(com.actiontech.dble.plan.node.JoinNode) TableNode(com.actiontech.dble.plan.node.TableNode) ERTable(com.actiontech.dble.config.model.ERTable) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 20 with JoinNode

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

the class ERJoinChooser method getERKey.

private ERTable getERKey(PlanNode tn, Item c) {
    if (!(c instanceof ItemField))
        return null;
    if (tn.type() != PlanNode.PlanNodeType.TABLE && !PlanUtil.isERNode(tn)) {
        return null;
    }
    Pair<TableNode, ItemField> pair = PlanUtil.findColumnInTableLeaf((ItemField) c, tn);
    if (pair == null)
        return null;
    TableNode tableNode = pair.getKey();
    ItemField col = pair.getValue();
    ERTable cm = new ERTable(tableNode.getSchema(), tableNode.getPureName(), col.getItemName());
    if (tn.type() == PlanNode.PlanNodeType.TABLE) {
        return cm;
    } else {
        List<ERTable> erList = ((JoinNode) tn).getERkeys();
        for (ERTable cerKey : erList) {
            if (isErRelation(cm, cerKey))
                return cm;
        }
        return null;
    }
}
Also used : JoinNode(com.actiontech.dble.plan.node.JoinNode) TableNode(com.actiontech.dble.plan.node.TableNode) ERTable(com.actiontech.dble.config.model.ERTable) ItemField(com.actiontech.dble.plan.common.item.ItemField)

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