Search in sources :

Example 1 with BaseHandlerBuilder

use of com.actiontech.dble.backend.mysql.nio.handler.builder.BaseHandlerBuilder in project dble by actiontech.

the class ExplainHandler method getBaseHandlerBuilders.

private static List<BaseHandlerBuilder> getBaseHandlerBuilders(RouteResultset rrs, ServerConnection c) {
    BaseHandlerBuilder builder = buildNodes(rrs, c);
    Queue<BaseHandlerBuilder> queue = new LinkedList<>();
    queue.add(builder);
    List<BaseHandlerBuilder> builderList = new ArrayList<>();
    while (queue.size() > 0) {
        BaseHandlerBuilder rootBuilder = queue.poll();
        builderList.add(rootBuilder);
        if (rootBuilder.getSubQueryBuilderList().size() > 0) {
            queue.addAll(rootBuilder.getSubQueryBuilderList());
        }
    }
    return builderList;
}
Also used : BaseHandlerBuilder(com.actiontech.dble.backend.mysql.nio.handler.builder.BaseHandlerBuilder)

Example 2 with BaseHandlerBuilder

use of com.actiontech.dble.backend.mysql.nio.handler.builder.BaseHandlerBuilder in project dble by actiontech.

the class ExplainHandler method buildNodes.

private static BaseHandlerBuilder buildNodes(RouteResultset rrs, ServerConnection c) {
    SQLSelectStatement ast = (SQLSelectStatement) rrs.getSqlStatement();
    MySQLPlanNodeVisitor visitor = new MySQLPlanNodeVisitor(c.getSchema(), c.getCharset().getResultsIndex(), DbleServer.getInstance().getTmManager(), false);
    visitor.visit(ast);
    PlanNode node = visitor.getTableNode();
    node.setSql(rrs.getStatement());
    node.setUpFields();
    PlanUtil.checkTablesPrivilege(c, node, ast);
    node = MyOptimizer.optimize(node);
    if (!PlanUtil.containsSubQuery(node) && !visitor.isContainSchema()) {
        node.setAst(ast);
    }
    HandlerBuilder builder = new HandlerBuilder(node, c.getSession2());
    return builder.getBuilder(c.getSession2(), node, true);
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySQLPlanNodeVisitor(com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor) HandlerBuilder(com.actiontech.dble.backend.mysql.nio.handler.builder.HandlerBuilder) BaseHandlerBuilder(com.actiontech.dble.backend.mysql.nio.handler.builder.BaseHandlerBuilder)

Example 3 with BaseHandlerBuilder

use of com.actiontech.dble.backend.mysql.nio.handler.builder.BaseHandlerBuilder in project dble by actiontech.

the class ExplainHandler method getComplexQueryResult.

private static List<String[]> getComplexQueryResult(RouteResultset rrs, ServerConnection c) {
    List<BaseHandlerBuilder> builderList = getBaseHandlerBuilders(rrs, c);
    Map<String, Integer> nameMap = new HashMap<>();
    List<String[]> result = new ArrayList<>();
    Map<BaseHandlerBuilder, String> builderNameMap = new HashMap<>();
    for (int i = builderList.size() - 1; i >= 0; i--) {
        BaseHandlerBuilder tmpBuilder = builderList.get(i);
        Set<String> subQueries = new LinkedHashSet<>();
        for (BaseHandlerBuilder childBuilder : tmpBuilder.getSubQueryBuilderList()) {
            subQueries.add(builderNameMap.get(childBuilder));
        }
        String subQueryRootName = buildResultByEndHandler(subQueries, result, tmpBuilder.getEndHandler(), nameMap);
        builderNameMap.put(tmpBuilder, subQueryRootName);
    }
    return result;
}
Also used : BaseHandlerBuilder(com.actiontech.dble.backend.mysql.nio.handler.builder.BaseHandlerBuilder)

Aggregations

BaseHandlerBuilder (com.actiontech.dble.backend.mysql.nio.handler.builder.BaseHandlerBuilder)3 HandlerBuilder (com.actiontech.dble.backend.mysql.nio.handler.builder.HandlerBuilder)1 PlanNode (com.actiontech.dble.plan.node.PlanNode)1 MySQLPlanNodeVisitor (com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)1 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)1