Search in sources :

Example 1 with TableNode

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

the class BaseHandlerBuilder method build.

/**
 * generate a handler chain
 */
public final void build() {
    List<DMLResponseHandler> preHandlers = null;
    // is use the nest loop join
    boolean isNestLoopJoin = isNestLoopStrategy(node);
    if (isNestLoopJoin) {
        nestLoopBuild();
    } else if (!node.isExistView() && PlanUtil.isGlobal(node) && !node.isSubQuery()) {
        // the query can be send to a certain node
        noShardBuild();
    } else if (canDoAsMerge()) {
        // the query can be send to some certain nodes .eg: ER tables,  GLOBAL*NORMAL GLOBAL*ER
        mergeBuild();
    } else {
        handleSubQueries();
        // need to split to simple query
        preHandlers = buildPre();
        buildOwn();
    }
    if (needCommon) {
        buildCommon();
    }
    // view sub alias
    String tbAlias = node.getAlias();
    String schema = null;
    String table = null;
    if (node.type() == PlanNodeType.TABLE) {
        TableNode tbNode = (TableNode) node;
        schema = tbNode.getSchema();
        table = tbNode.getTableName();
    }
    if (node.type() != PlanNodeType.NONAME) {
        SendMakeHandler sh = new SendMakeHandler(getSequenceId(), session, node.getColumnsSelected(), schema, table, tbAlias);
        addHandler(sh);
    }
    if (preHandlers != null) {
        for (DMLResponseHandler preHandler : preHandlers) {
            preHandler.setNextHandler(start);
        }
    }
}
Also used : DMLResponseHandler(com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler) TableNode(com.actiontech.dble.plan.node.TableNode)

Example 2 with TableNode

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

the class JoinStrategyChooser method tryLeftJoinNestLoop.

/**
 * @param jn
 * @return
 */
private boolean tryLeftJoinNestLoop() {
    TableNode tnLeft = (TableNode) jn.getLeftNode();
    TableNode tnRight = (TableNode) jn.getRightNode();
    // left join and only left node has where filter
    if (isSmallTable(tnLeft) && !isSmallTable(tnRight)) {
        handleNestLoopStrategy(true);
        return true;
    } else {
        return false;
    }
}
Also used : TableNode(com.actiontech.dble.plan.node.TableNode)

Example 3 with TableNode

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

the class JoinStrategyChooser method handleNestLoopStrategy.

private void handleNestLoopStrategy(boolean isLeftSmall) {
    jn.setStrategy(Strategy.NESTLOOP);
    TableNode tnLeft = (TableNode) jn.getLeftNode();
    TableNode tnRight = (TableNode) jn.getRightNode();
    TableNode tnBig = isLeftSmall ? tnRight : tnLeft;
    tnBig.setNestLoopFilters(new ArrayList<Item>());
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) TableNode(com.actiontech.dble.plan.node.TableNode)

Example 4 with TableNode

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

the class MyOptimizer method checkGlobalTable.

/**
 * existShardTable
 *
 * @param node
 * @return return 1 if it's all no name table or all global table node;
 * return -1 if all the table is not global table,need not global optimizer;
 * return 0 for other ,may need to global optimizer ;
 */
public static int checkGlobalTable(PlanNode node, Set<String> resultDataNodes) {
    if (node.isSubQuery()) {
        return 0;
    }
    Set<String> dataNodes = null;
    boolean isAllGlobal = true;
    boolean isContainGlobal = false;
    for (TableNode tn : node.getReferedTableNodes()) {
        if (tn.getUnGlobalTableCount() == 0) {
            isContainGlobal = true;
            if (isAllGlobal) {
                if (dataNodes == null) {
                    dataNodes = new HashSet<>();
                    dataNodes.addAll(tn.getNoshardNode());
                } else {
                    dataNodes.retainAll(tn.getNoshardNode());
                }
            } else {
                return 0;
            }
        } else {
            isAllGlobal = false;
            if (isContainGlobal) {
                return 0;
            }
        }
    }
    if (isAllGlobal) {
        if (dataNodes == null) {
            // all nonamenode
            String db = SchemaUtil.getRandomDb();
            SchemaConfig schemaConfig = DbleServer.getInstance().getConfig().getSchemas().get(db);
            node.setNoshardNode(schemaConfig.getAllDataNodes());
            resultDataNodes.addAll(schemaConfig.getAllDataNodes());
            return 1;
        } else if (dataNodes.size() > 0) {
            // all global table
            node.setNoshardNode(dataNodes);
            resultDataNodes.addAll(dataNodes);
            String sql = node.getSql();
            for (TableNode tn : node.getReferedTableNodes()) {
                sql = RouterUtil.removeSchema(sql, tn.getSchema());
            }
            node.setSql(sql);
            return 1;
        } else {
            return 0;
        }
    }
    return -1;
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) TableNode(com.actiontech.dble.plan.node.TableNode)

Example 5 with TableNode

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

the class FilterJoinColumnPusher method isPossibleERJoinColumnFilter.

/**
 * is ER Filter: 1.Filter must be equal(=) 2.Filter must be Column = Column
 * 3.Filter's key and value must be belong different table ex:a.id=b.id true a.id=b.id+1 false
 */
private static boolean isPossibleERJoinColumnFilter(PlanNode node, Item ifilter) {
    if (!(ifilter instanceof ItemFuncEqual))
        return false;
    ItemFuncEqual filter = (ItemFuncEqual) ifilter;
    Item column = filter.arguments().get(0);
    Item value = filter.arguments().get(1);
    if (column != null && column instanceof ItemField && value != null && value instanceof ItemField) {
        Pair<TableNode, ItemField> foundColumn = PlanUtil.findColumnInTableLeaf((ItemField) column, node);
        Pair<TableNode, ItemField> foundValue = PlanUtil.findColumnInTableLeaf((ItemField) value, node);
        if (foundColumn != null && foundValue != null) {
            String columnTable = foundColumn.getValue().getTableName();
            String valueTable = foundValue.getValue().getTableName();
            // the table must be different
            return !StringUtils.equals(columnTable, valueTable);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual) TableNode(com.actiontech.dble.plan.node.TableNode) 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