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;
}
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);
}
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;
}
Aggregations