use of com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor in project dble by actiontech.
the class NonBlockingSession method executeMultiSelect.
private void executeMultiSelect(RouteResultset rrs) {
SQLSelectStatement ast = (SQLSelectStatement) rrs.getSqlStatement();
MySQLPlanNodeVisitor visitor = new MySQLPlanNodeVisitor(this.getSource().getSchema(), this.getSource().getCharset().getResultsIndex(), DbleServer.getInstance().getTmManager(), false);
visitor.visit(ast);
PlanNode node = visitor.getTableNode();
if (node.isCorrelatedSubQuery()) {
throw new MySQLOutPutException(ErrorCode.ER_UNKNOWN_ERROR, "", "Correlated Sub Queries is not supported ");
}
node.setSql(rrs.getStatement());
node.setUpFields();
PlanUtil.checkTablesPrivilege(source, node, ast);
node = MyOptimizer.optimize(node);
if (PlanUtil.containsSubQuery(node)) {
final PlanNode finalNode = node;
DbleServer.getInstance().getComplexQueryExecutor().execute(new Runnable() {
// sub Query build will be blocked, so use ComplexQueryExecutor
@Override
public void run() {
executeMultiResultSet(finalNode);
}
});
} else {
if (!visitor.isContainSchema()) {
node.setAst(ast);
}
executeMultiResultSet(node);
}
}
use of com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor in project dble by actiontech.
the class ItemSubQuery method init.
private void init() {
MySQLPlanNodeVisitor pv = new MySQLPlanNodeVisitor(currentDb, charsetIndex, metaManager, true);
pv.visit(this.query);
this.planNode = pv.getTableNode();
if (planNode.type() != PlanNode.PlanNodeType.NONAME) {
this.withSubQuery = true;
PlanNode test = this.planNode.copy();
try {
test.setUpFields();
} catch (Exception e) {
this.correlatedSubQuery = true;
}
}
}
use of com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor 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.plan.visitor.MySQLPlanNodeVisitor in project dble by actiontech.
the class ViewMeta method init.
public ErrorPacket init(boolean isReplace) {
ViewMetaParser viewParser = new ViewMetaParser(createSql);
try {
viewParser.parseCreateView(this);
// check if the select part has
this.checkDuplicate(viewParser, isReplace);
SQLSelectStatement selectStatement = (SQLSelectStatement) RouteStrategyFactory.getRouteStrategy().parserSQL(selectSql);
MySQLPlanNodeVisitor msv = new MySQLPlanNodeVisitor(this.schema, 63, tmManager, true);
msv.visit(selectStatement.getSelect().getQuery());
PlanNode selNode = msv.getTableNode();
selNode.setUpFields();
// set the view column name into
this.setFieldsAlias(selNode);
viewQuery = new QueryNode(selNode);
} catch (Exception e) {
// the select part sql is wrong & report the error
ErrorPacket error = new ErrorPacket();
error.setMessage(e.getMessage() == null ? "unknow error".getBytes(StandardCharsets.UTF_8) : e.getMessage().getBytes(StandardCharsets.UTF_8));
error.setErrNo(CREATE_VIEW_ERROR);
return error;
}
return null;
}
use of com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor in project dble by actiontech.
the class ViewMeta method initAndSet.
public ErrorPacket initAndSet(boolean isReplace) {
// check the create sql is legal
// parse sql into three parts
ViewMetaParser viewParser = new ViewMetaParser(createSql);
viewParser.parseCreateView(this);
try {
if ("".equals(viewName)) {
throw new Exception("sql not supported ");
}
tmManager.addMetaLock(schema, viewName);
// check if the select part has
this.checkDuplicate(viewParser, isReplace);
SQLSelectStatement selectStatement = (SQLSelectStatement) RouteStrategyFactory.getRouteStrategy().parserSQL(selectSql);
MySQLPlanNodeVisitor msv = new MySQLPlanNodeVisitor(this.schema, 63, tmManager, true);
msv.visit(selectStatement.getSelect().getQuery());
PlanNode selNode = msv.getTableNode();
selNode.setUpFields();
// set the view column name into
this.setFieldsAlias(selNode);
viewQuery = new QueryNode(selNode);
tmManager.getCatalogs().get(schema).getViewMetas().put(viewName, this);
} catch (Exception e) {
// the select part sql is wrong & report the error
ErrorPacket error = new ErrorPacket();
error.setMessage(e.getMessage() == null ? "unknown error".getBytes(StandardCharsets.UTF_8) : e.getMessage().getBytes(StandardCharsets.UTF_8));
error.setErrNo(CREATE_VIEW_ERROR);
return error;
} finally {
tmManager.removeMetaLock(schema, viewName);
}
return null;
}
Aggregations