Search in sources :

Example 21 with StatsProvider

use of io.trino.cost.StatsProvider 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

StatsProvider (io.trino.cost.StatsProvider)21 PlanNode (io.trino.sql.planner.plan.PlanNode)15 Session (io.trino.Session)14 Metadata (io.trino.metadata.Metadata)14 List (java.util.List)14 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)13 Preconditions.checkState (com.google.common.base.Preconditions.checkState)13 NO_MATCH (io.trino.sql.planner.assertions.MatchResult.NO_MATCH)13 Optional (java.util.Optional)12 Objects.requireNonNull (java.util.Objects.requireNonNull)11 MatchResult.match (io.trino.sql.planner.assertions.MatchResult.match)9 Symbol (io.trino.sql.planner.Symbol)8 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)6 CachingStatsProvider (io.trino.cost.CachingStatsProvider)5 Map (java.util.Map)5 Set (java.util.Set)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 CachingCostProvider (io.trino.cost.CachingCostProvider)4 CostProvider (io.trino.cost.CostProvider)4