Use precomputed stats in MetricComparator
This way stats computation remains within the transaction.
@@ -15,12 +15,9 @@ package com.facebook.presto.tests.statistics;
import com.facebook.presto.Session;
import com.facebook.presto.cost.PlanNodeStatsEstimate;
-import com.facebook.presto.cost.StatsCalculator;
import com.facebook.presto.sql.planner.Plan;
import com.facebook.presto.sql.planner.Symbol;
-import com.facebook.presto.sql.planner.TypeProvider;
import com.facebook.presto.sql.planner.plan.OutputNode;
-import com.facebook.presto.sql.planner.plan.PlanNode;
import com.facebook.presto.testing.MaterializedRow;
import com.facebook.presto.testing.QueryRunner;
import com.google.common.collect.ImmutableList;
@@ -29,7 +26,7 @@ import com.google.common.collect.ImmutableMap;
import java.util.List;
import java.util.OptionalDouble;
-import static com.facebook.presto.sql.planner.iterative.Lookup.noLookup;
+import static com.facebook.presto.cost.PlanNodeStatsEstimate.UNKNOWN_STATS;
import static com.facebook.presto.transaction.TransactionBuilder.transaction;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.getOnlyElement;
@@ -68,22 +65,11 @@ final class MetricComparator
{
Plan queryPlan = runner.createPlan(session, query);
OutputNode outputNode = (OutputNode) queryPlan.getRoot();
- PlanNodeStatsEstimate outputNodeStats = calculateStats(outputNode, runner.getStatsCalculator(), session, queryPlan.getTypes());
+ PlanNodeStatsEstimate outputNodeStats = queryPlan.getStatsAndCosts().getStats().getOrDefault(queryPlan.getRoot().getId(), UNKNOWN_STATS);
StatsContext statsContext = buildStatsContext(queryPlan, outputNode);
return getEstimatedValues(metrics, outputNodeStats, statsContext);
}
- private static PlanNodeStatsEstimate calculateStats(PlanNode node, StatsCalculator statsCalculator, Session session, TypeProvider types)
- {
- // We calculate stats one-off, so caching is not necessary
- return statsCalculator.calculateStats(
- node,
- source -> calculateStats(source, statsCalculator, session, types),
- noLookup(),
- session,
- types);
- }
-
private static StatsContext buildStatsContext(Plan queryPlan, OutputNode outputNode)
{
ImmutableMap.Builder<String, Symbol> columnSymbols = ImmutableMap.builder();
