Search in sources :

Example 1 with StatsAndCosts

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

the class QueryMonitor method createQueryStatistics.

private QueryStatistics createQueryStatistics(QueryInfo queryInfo) {
    ImmutableList.Builder<String> operatorSummaries = ImmutableList.builder();
    for (OperatorStats summary : queryInfo.getQueryStats().getOperatorSummaries()) {
        operatorSummaries.add(operatorStatsCodec.toJson(summary));
    }
    Optional<StatsAndCosts> planNodeStatsAndCosts = queryInfo.getOutputStage().map(StatsAndCosts::create);
    Optional<String> serializedPlanNodeStatsAndCosts = planNodeStatsAndCosts.map(statsAndCostsCodec::toJson);
    QueryStats queryStats = queryInfo.getQueryStats();
    return new QueryStatistics(ofMillis(queryStats.getTotalCpuTime().toMillis()), ofMillis(queryStats.getFailedCpuTime().toMillis()), ofMillis(queryStats.getElapsedTime().toMillis()), ofMillis(queryStats.getQueuedTime().toMillis()), Optional.of(ofMillis(queryStats.getTotalScheduledTime().toMillis())), Optional.of(ofMillis(queryStats.getFailedScheduledTime().toMillis())), Optional.of(ofMillis(queryStats.getResourceWaitingTime().toMillis())), Optional.of(ofMillis(queryStats.getAnalysisTime().toMillis())), Optional.of(ofMillis(queryStats.getPlanningTime().toMillis())), Optional.of(ofMillis(queryStats.getExecutionTime().toMillis())), queryStats.getPeakUserMemoryReservation().toBytes(), queryStats.getPeakTaskUserMemory().toBytes(), queryStats.getPeakTaskTotalMemory().toBytes(), queryStats.getPhysicalInputDataSize().toBytes(), queryStats.getPhysicalInputPositions(), queryStats.getInternalNetworkInputDataSize().toBytes(), queryStats.getInternalNetworkInputPositions(), queryStats.getRawInputDataSize().toBytes(), queryStats.getRawInputPositions(), queryStats.getOutputDataSize().toBytes(), queryStats.getOutputPositions(), queryStats.getLogicalWrittenDataSize().toBytes(), queryStats.getWrittenPositions(), queryStats.getCumulativeUserMemory(), queryStats.getFailedCumulativeUserMemory(), queryStats.getStageGcStatistics(), queryStats.getCompletedDrivers(), queryInfo.isCompleteInfo(), getCpuDistributions(queryInfo), operatorSummaries.build(), serializedPlanNodeStatsAndCosts);
}
Also used : QueryStats(io.trino.execution.QueryStats) QueryStatistics(io.trino.spi.eventlistener.QueryStatistics) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) StatsAndCosts(io.trino.cost.StatsAndCosts) OperatorStats(io.trino.operator.OperatorStats)

Example 2 with StatsAndCosts

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

StatsAndCosts (io.trino.cost.StatsAndCosts)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 CachingCostProvider (io.trino.cost.CachingCostProvider)1 CachingStatsProvider (io.trino.cost.CachingStatsProvider)1 CostProvider (io.trino.cost.CostProvider)1 StatsProvider (io.trino.cost.StatsProvider)1 QueryStats (io.trino.execution.QueryStats)1 OperatorStats (io.trino.operator.OperatorStats)1 QueryStatistics (io.trino.spi.eventlistener.QueryStatistics)1 PlanOptimizer (io.trino.sql.planner.optimizations.PlanOptimizer)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1