Search in sources :

Example 6 with TableNode

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

Example 7 with TableNode

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

the class JoinStrategyChooser method tryInnerJoinNestLoop.

/**
 * @param jn
 * @return
 */
private boolean tryInnerJoinNestLoop() {
    TableNode tnLeft = (TableNode) jn.getLeftNode();
    TableNode tnRight = (TableNode) jn.getRightNode();
    boolean isLeftSmall = isSmallTable(tnLeft);
    boolean isRightSmall = isSmallTable(tnRight);
    if (isLeftSmall && isRightSmall)
        return false;
    else if (!isLeftSmall && !isRightSmall)
        return false;
    else {
        handleNestLoopStrategy(isLeftSmall);
        return true;
    }
}
Also used : TableNode(com.actiontech.dble.plan.node.TableNode)

Example 8 with TableNode

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

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

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

TableNode (com.actiontech.dble.plan.node.TableNode)10 ItemField (com.actiontech.dble.plan.common.item.ItemField)3 ERTable (com.actiontech.dble.config.model.ERTable)2 Item (com.actiontech.dble.plan.common.item.Item)2 JoinNode (com.actiontech.dble.plan.node.JoinNode)2 PlanNode (com.actiontech.dble.plan.node.PlanNode)2 DMLResponseHandler (com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler)1 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)1 NamedField (com.actiontech.dble.plan.NamedField)1 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)1 ItemSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemSubQuery)1 ArrayList (java.util.ArrayList)1