Search in sources :

Example 1 with MySQLPlanNodeVisitor

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);
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySQLPlanNodeVisitor(com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 2 with MySQLPlanNodeVisitor

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;
        }
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) MySQLPlanNodeVisitor(com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)

Example 3 with MySQLPlanNodeVisitor

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);
}
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 4 with MySQLPlanNodeVisitor

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;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) QueryNode(com.actiontech.dble.plan.node.QueryNode) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySQLPlanNodeVisitor(com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)

Example 5 with MySQLPlanNodeVisitor

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;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) QueryNode(com.actiontech.dble.plan.node.QueryNode) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySQLPlanNodeVisitor(com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)

Aggregations

PlanNode (com.actiontech.dble.plan.node.PlanNode)5 MySQLPlanNodeVisitor (com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)5 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)4 ErrorPacket (com.actiontech.dble.net.mysql.ErrorPacket)2 QueryNode (com.actiontech.dble.plan.node.QueryNode)2 BaseHandlerBuilder (com.actiontech.dble.backend.mysql.nio.handler.builder.BaseHandlerBuilder)1 HandlerBuilder (com.actiontech.dble.backend.mysql.nio.handler.builder.HandlerBuilder)1 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)1