Search in sources :

Example 1 with LogicalPlanner

use of io.trino.sql.planner.LogicalPlanner in project trino by trinodb.

the class SqlQueryExecution method doPlanQuery.

private PlanRoot doPlanQuery() {
    // plan query
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    LogicalPlanner logicalPlanner = new LogicalPlanner(stateMachine.getSession(), planOptimizers, idAllocator, plannerContext, typeAnalyzer, statsCalculator, costCalculator, stateMachine.getWarningCollector());
    Plan plan = logicalPlanner.plan(analysis);
    queryPlan.set(plan);
    // fragment the plan
    SubPlan fragmentedPlan = planFragmenter.createSubPlans(stateMachine.getSession(), plan, false, stateMachine.getWarningCollector());
    // extract inputs
    List<Input> inputs = new InputExtractor(plannerContext.getMetadata(), stateMachine.getSession()).extractInputs(fragmentedPlan);
    stateMachine.setInputs(inputs);
    stateMachine.setOutput(analysis.getTarget());
    boolean explainAnalyze = analysis.getStatement() instanceof ExplainAnalyze;
    return new PlanRoot(fragmentedPlan, !explainAnalyze);
}
Also used : LogicalPlanner(io.trino.sql.planner.LogicalPlanner) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) InputExtractor(io.trino.sql.planner.InputExtractor) SubPlan(io.trino.sql.planner.SubPlan) Plan(io.trino.sql.planner.Plan) SubPlan(io.trino.sql.planner.SubPlan)

Example 2 with LogicalPlanner

use of io.trino.sql.planner.LogicalPlanner in project trino by trinodb.

the class LocalQueryRunner method createPlan.

public Plan createPlan(Session session, @Language("SQL") String sql, List<PlanOptimizer> optimizers, LogicalPlanner.Stage stage, WarningCollector warningCollector) {
    PreparedQuery preparedQuery = new QueryPreparer(sqlParser).prepareQuery(session, sql);
    assertFormattedSql(sqlParser, createParsingOptions(session), preparedQuery.getStatement());
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    AnalyzerFactory analyzerFactory = createAnalyzerFactory(createQueryExplainerFactory(optimizers));
    Analyzer analyzer = analyzerFactory.createAnalyzer(session, preparedQuery.getParameters(), parameterExtractor(preparedQuery.getStatement(), preparedQuery.getParameters()), warningCollector);
    LogicalPlanner logicalPlanner = new LogicalPlanner(session, optimizers, new PlanSanityChecker(true), idAllocator, getPlannerContext(), new TypeAnalyzer(plannerContext, statementAnalyzerFactory), statsCalculator, costCalculator, warningCollector);
    Analysis analysis = analyzer.analyze(preparedQuery.getStatement());
    // make LocalQueryRunner always compute plan statistics for test purposes
    return logicalPlanner.plan(analysis, stage);
}
Also used : QueryPreparer(io.trino.execution.QueryPreparer) LogicalPlanner(io.trino.sql.planner.LogicalPlanner) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Analysis(io.trino.sql.analyzer.Analysis) PreparedQuery(io.trino.execution.QueryPreparer.PreparedQuery) PlanSanityChecker(io.trino.sql.planner.sanity.PlanSanityChecker) Analyzer(io.trino.sql.analyzer.Analyzer) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer) StatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory) AnalyzerFactory(io.trino.sql.analyzer.AnalyzerFactory)

Example 3 with LogicalPlanner

use of io.trino.sql.planner.LogicalPlanner in project trino by trinodb.

the class QueryExplainer method getLogicalPlan.

public Plan getLogicalPlan(Session session, Statement statement, List<Expression> parameters, WarningCollector warningCollector) {
    // analyze statement
    Analysis analysis = analyze(session, statement, parameters, warningCollector);
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    // plan statement
    LogicalPlanner logicalPlanner = new LogicalPlanner(session, planOptimizers, idAllocator, plannerContext, new TypeAnalyzer(plannerContext, statementAnalyzerFactory), statsCalculator, costCalculator, warningCollector);
    return logicalPlanner.plan(analysis, OPTIMIZED_AND_VALIDATED, true);
}
Also used : LogicalPlanner(io.trino.sql.planner.LogicalPlanner) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer)

Aggregations

LogicalPlanner (io.trino.sql.planner.LogicalPlanner)3 PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)3 TypeAnalyzer (io.trino.sql.planner.TypeAnalyzer)2 QueryPreparer (io.trino.execution.QueryPreparer)1 PreparedQuery (io.trino.execution.QueryPreparer.PreparedQuery)1 Analysis (io.trino.sql.analyzer.Analysis)1 Analyzer (io.trino.sql.analyzer.Analyzer)1 AnalyzerFactory (io.trino.sql.analyzer.AnalyzerFactory)1 StatementAnalyzerFactory (io.trino.sql.analyzer.StatementAnalyzerFactory)1 InputExtractor (io.trino.sql.planner.InputExtractor)1 Plan (io.trino.sql.planner.Plan)1 SubPlan (io.trino.sql.planner.SubPlan)1 PlanSanityChecker (io.trino.sql.planner.sanity.PlanSanityChecker)1 ExplainAnalyze (io.trino.sql.tree.ExplainAnalyze)1