Search in sources :

Example 1 with PlanCostEstimate

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

the class TestMemo method testEvictCostOnReplace.

@Test
public void testEvictCostOnReplace() {
    PlanNode y = node();
    PlanNode x = node(y);
    Memo memo = new Memo(idAllocator, x);
    int xGroup = memo.getRootGroup();
    int yGroup = getChildGroup(memo, memo.getRootGroup());
    PlanCostEstimate yCost = new PlanCostEstimate(42, 0, 0, 0);
    PlanCostEstimate xCost = new PlanCostEstimate(42, 0, 0, 37);
    memo.storeCost(yGroup, yCost);
    memo.storeCost(xGroup, xCost);
    assertEquals(memo.getCost(yGroup), Optional.of(yCost));
    assertEquals(memo.getCost(xGroup), Optional.of(xCost));
    memo.replace(yGroup, node(), "rule");
    assertEquals(memo.getCost(yGroup), Optional.empty());
    assertEquals(memo.getCost(xGroup), Optional.empty());
}
Also used : PlanCostEstimate(io.trino.cost.PlanCostEstimate) PlanNode(io.trino.sql.planner.plan.PlanNode) Test(org.testng.annotations.Test)

Example 2 with PlanCostEstimate

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

the class TextRenderer method printEstimates.

private String printEstimates(PlanRepresentation plan, NodeRepresentation node) {
    if (node.getEstimatedStats().stream().allMatch(PlanNodeStatsEstimate::isOutputRowCountUnknown) && node.getEstimatedCost().stream().allMatch(c -> c.equals(PlanCostEstimate.unknown()))) {
        return "";
    }
    StringBuilder output = new StringBuilder();
    int estimateCount = node.getEstimatedStats().size();
    output.append("Estimates: ");
    for (int i = 0; i < estimateCount; i++) {
        PlanNodeStatsEstimate stats = node.getEstimatedStats().get(i);
        PlanCostEstimate cost = node.getEstimatedCost().get(i);
        List<Symbol> outputSymbols = node.getOutputs().stream().map(TypedSymbol::getSymbol).collect(toList());
        output.append(format("{rows: %s (%s), cpu: %s, memory: %s, network: %s}", formatAsLong(stats.getOutputRowCount()), formatAsDataSize(stats.getOutputSizeInBytes(outputSymbols, plan.getTypes())), formatAsCpuCost(cost.getCpuCost()), formatAsDataSize(cost.getMaxMemory()), formatAsDataSize(cost.getNetworkCost())));
        if (i < estimateCount - 1) {
            output.append("/");
        }
    }
    output.append("\n");
    return output.toString();
}
Also used : POSITIVE_INFINITY(java.lang.Double.POSITIVE_INFINITY) PlanCostEstimate(io.trino.cost.PlanCostEstimate) Function(java.util.function.Function) Metric(io.trino.spi.metrics.Metric) NEGATIVE_INFINITY(java.lang.Double.NEGATIVE_INFINITY) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Metrics(io.trino.spi.metrics.Metrics) TypedSymbol(io.trino.sql.planner.planprinter.NodeRepresentation.TypedSymbol) Verify.verify(com.google.common.base.Verify.verify) Locale(java.util.Locale) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Double.isFinite(java.lang.Double.isFinite) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) Symbol(io.trino.sql.planner.Symbol) Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) PlanNodeStatsAndCostSummary(io.trino.cost.PlanNodeStatsAndCostSummary) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) DataSize(io.airlift.units.DataSize) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TreeMap(java.util.TreeMap) Double.isNaN(java.lang.Double.isNaN) Optional(java.util.Optional) PlanCostEstimate(io.trino.cost.PlanCostEstimate) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) TypedSymbol(io.trino.sql.planner.planprinter.NodeRepresentation.TypedSymbol) Symbol(io.trino.sql.planner.Symbol)

Aggregations

PlanCostEstimate (io.trino.cost.PlanCostEstimate)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 DataSize (io.airlift.units.DataSize)1 PlanNodeStatsAndCostSummary (io.trino.cost.PlanNodeStatsAndCostSummary)1 PlanNodeStatsEstimate (io.trino.cost.PlanNodeStatsEstimate)1 Metric (io.trino.spi.metrics.Metric)1 Metrics (io.trino.spi.metrics.Metrics)1 Symbol (io.trino.sql.planner.Symbol)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1 TypedSymbol (io.trino.sql.planner.planprinter.NodeRepresentation.TypedSymbol)1 NEGATIVE_INFINITY (java.lang.Double.NEGATIVE_INFINITY)1 POSITIVE_INFINITY (java.lang.Double.POSITIVE_INFINITY)1 Double.isFinite (java.lang.Double.isFinite)1 Double.isNaN (java.lang.Double.isNaN)1 String.format (java.lang.String.format)1 Iterator (java.util.Iterator)1 List (java.util.List)1