Search in sources :

Example 6 with CachingStatsProvider

use of io.trino.cost.CachingStatsProvider in project trino by trinodb.

the class LogicalPlanner method plan.

public Plan plan(Analysis analysis, Stage stage, boolean collectPlanStatistics) {
    PlanNode root = planStatement(analysis, analysis.getStatement());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Initial plan:\n%s", PlanPrinter.textLogicalPlan(root, symbolAllocator.getTypes(), metadata, plannerContext.getFunctionManager(), StatsAndCosts.empty(), session, 0, false));
    }
    planSanityChecker.validateIntermediatePlan(root, session, plannerContext, typeAnalyzer, symbolAllocator.getTypes(), warningCollector);
    if (stage.ordinal() >= OPTIMIZED.ordinal()) {
        for (PlanOptimizer optimizer : planOptimizers) {
            root = optimizer.optimize(root, session, symbolAllocator.getTypes(), symbolAllocator, idAllocator, warningCollector);
            requireNonNull(root, format("%s returned a null plan", optimizer.getClass().getName()));
            if (LOG.isDebugEnabled()) {
                LOG.debug("%s:\n%s", optimizer.getClass().getName(), PlanPrinter.textLogicalPlan(root, symbolAllocator.getTypes(), metadata, plannerContext.getFunctionManager(), StatsAndCosts.empty(), session, 0, false));
            }
        }
    }
    if (stage.ordinal() >= OPTIMIZED_AND_VALIDATED.ordinal()) {
        // make sure we produce a valid plan after optimizations run. This is mainly to catch programming errors
        planSanityChecker.validateFinalPlan(root, session, plannerContext, typeAnalyzer, symbolAllocator.getTypes(), warningCollector);
    }
    TypeProvider types = symbolAllocator.getTypes();
    StatsAndCosts statsAndCosts = StatsAndCosts.empty();
    if (collectPlanStatistics) {
        StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, types);
        CostProvider costProvider = new CachingCostProvider(costCalculator, statsProvider, Optional.empty(), session, types);
        statsAndCosts = StatsAndCosts.create(root, statsProvider, costProvider);
    }
    return new Plan(root, types, statsAndCosts);
}
Also used : PlanOptimizer(io.trino.sql.planner.optimizations.PlanOptimizer) CachingStatsProvider(io.trino.cost.CachingStatsProvider) PlanNode(io.trino.sql.planner.plan.PlanNode) CachingStatsProvider(io.trino.cost.CachingStatsProvider) StatsProvider(io.trino.cost.StatsProvider) StatsAndCosts(io.trino.cost.StatsAndCosts) CachingCostProvider(io.trino.cost.CachingCostProvider) CostProvider(io.trino.cost.CostProvider) CachingCostProvider(io.trino.cost.CachingCostProvider)

Aggregations

CachingStatsProvider (io.trino.cost.CachingStatsProvider)6 CachingCostProvider (io.trino.cost.CachingCostProvider)5 StatsProvider (io.trino.cost.StatsProvider)5 CostProvider (io.trino.cost.CostProvider)4 StatsAndCosts (io.trino.cost.StatsAndCosts)1 PlannerContext (io.trino.sql.PlannerContext)1 PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)1 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)1 PlanOptimizer (io.trino.sql.planner.optimizations.PlanOptimizer)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1