@Override protected PlanNodeCostEstimate visitPlan(PlanNode node, Void context) { return PlanNodeCostEstimate.unknown(); }
private boolean isPlanNodeStatsAndCostsUnknown(PlanNode node) { PlanNodeStatsEstimate stats = estimatedStatsAndCosts.getStats().getOrDefault(node.getId(), PlanNodeStatsEstimate.unknown()); PlanNodeCostEstimate cost = estimatedStatsAndCosts.getCosts().getOrDefault(node.getId(), PlanNodeCostEstimate.unknown()); return stats.isOutputRowCountUnknown() || cost.equals(PlanNodeCostEstimate.unknown()); }
@Override public PlanNodeCostEstimate getCumulativeCost(PlanNode node) { if (!isEnableStatsCalculator(session)) { return PlanNodeCostEstimate.unknown(); } requireNonNull(node, "node is null"); try { if (node instanceof GroupReference) { return getGroupCost((GroupReference) node); } PlanNodeCostEstimate cumulativeCost = cache.get(node); if (cumulativeCost != null) { return cumulativeCost; } cumulativeCost = calculateCumulativeCost(node); verify(cache.put(node, cumulativeCost) == null, "Cost already set"); return cumulativeCost; } catch (RuntimeException e) { if (isIgnoreStatsCalculatorFailures(session)) { log.error(e, "Error occurred when computing cost for query %s", session.getQueryId()); return PlanNodeCostEstimate.unknown(); } throw e; } }
private String formatPlanNodeStatsAndCost(PlanNode node) { PlanNodeStatsEstimate stats = estimatedStatsAndCosts.getStats().getOrDefault(node.getId(), PlanNodeStatsEstimate.unknown()); PlanNodeCostEstimate cost = estimatedStatsAndCosts.getCosts().getOrDefault(node.getId(), PlanNodeCostEstimate.unknown()); return format("{rows: %s (%s), cpu: %s, memory: %s, network: %s}", formatAsLong(stats.getOutputRowCount()), formatEstimateAsDataSize(stats.getOutputSizeInBytes(node.getOutputSymbols(), types)), formatDouble(cost.getCpuCost()), formatDouble(cost.getMemoryCost()), formatDouble(cost.getNetworkCost())); } }
@Test public void testUnknownCost() { CostComparator costComparator = new CostComparator(1.0, 1.0, 1.0); Session session = testSessionBuilder().build(); assertThrows(IllegalArgumentException.class, () -> costComparator.compare(session, PlanNodeCostEstimate.zero(), PlanNodeCostEstimate.unknown())); assertThrows(IllegalArgumentException.class, () -> costComparator.compare(session, PlanNodeCostEstimate.unknown(), PlanNodeCostEstimate.zero())); assertThrows(IllegalArgumentException.class, () -> costComparator.compare(session, PlanNodeCostEstimate.unknown(), PlanNodeCostEstimate.unknown())); }
private PlanNodeCostEstimate calculateCumulativeCostFragmentedPlan(PlanNode node, StatsCalculator statsCalculator, Map<String, Type> types) { TypeProvider typeProvider = TypeProvider.copyOf(types.entrySet().stream() .collect(ImmutableMap.toImmutableMap(entry -> new Symbol(entry.getKey()), Map.Entry::getValue))); StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, typeProvider); CostProvider costProvider = new CachingCostProvider(costCalculatorUsingExchanges, statsProvider, Optional.empty(), session, typeProvider); SubPlan subPlan = fragment(new Plan(node, typeProvider, StatsAndCosts.create(node, statsProvider, costProvider))); return subPlan.getFragment().getStatsAndCosts().getCosts().getOrDefault(node.getId(), PlanNodeCostEstimate.unknown()); }
private CostAssertionBuilder assertCostFragmentedPlan( PlanNode node, Map<String, PlanNodeCostEstimate> costs, Map<String, PlanNodeStatsEstimate> stats, Map<String, Type> types) { TypeProvider typeProvider = TypeProvider.copyOf(types.entrySet().stream() .collect(ImmutableMap.toImmutableMap(entry -> new Symbol(entry.getKey()), Map.Entry::getValue))); StatsProvider statsProvider = new CachingStatsProvider(statsCalculator(stats), session, typeProvider); CostProvider costProvider = new TestingCostProvider(costs, costCalculatorUsingExchanges, statsProvider, session, typeProvider); SubPlan subPlan = fragment(new Plan(node, typeProvider, StatsAndCosts.create(node, statsProvider, costProvider))); return new CostAssertionBuilder(subPlan.getFragment().getStatsAndCosts().getCosts().getOrDefault(node.getId(), PlanNodeCostEstimate.unknown())); }
private void assertCostHasUnknownComponentsForUnknownStats(PlanNode node, Map<String, Type> types) { new CostAssertionBuilder(calculateCumulativeCost( costCalculatorUsingExchanges, node, planNode -> PlanNodeCostEstimate.unknown(), planNode -> PlanNodeStatsEstimate.unknown(), types)) .hasUnknownComponents(); new CostAssertionBuilder(calculateCumulativeCost( costCalculatorWithEstimatedExchanges, node, planNode -> PlanNodeCostEstimate.unknown(), planNode -> PlanNodeStatsEstimate.unknown(), types)) .hasUnknownComponents(); }
@Override public PlanNodeCostEstimate visitAggregation(AggregationNode node, Void context) { if (node.getStep() != FINAL && node.getStep() != SINGLE) { return PlanNodeCostEstimate.unknown(); } PlanNodeStatsEstimate aggregationStats = getStats(node); PlanNodeStatsEstimate sourceStats = getStats(node.getSource()); double cpuCost = sourceStats.getOutputSizeInBytes(node.getSource().getOutputSymbols(), types); double memoryCost = aggregationStats.getOutputSizeInBytes(node.getOutputSymbols(), types); return new PlanNodeCostEstimate(cpuCost, memoryCost, 0); }