Search in sources :

Example 6 with PlanNodeStatsEstimate

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

the class TestDetermineSemiJoinDistributionType method testReplicatesWhenSourceIsSmall.

@Test
public void testReplicatesWhenSourceIsSmall() {
    // variable width so that average row size is respected
    Type symbolType = createUnboundedVarcharType();
    int aRows = 10_000;
    int bRows = 10;
    PlanNodeStatsEstimate probeSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addSymbolStatistics(ImmutableMap.of(new Symbol("A1"), new SymbolStatsEstimate(0, 100, 0, 640000d * 10000, 10))).build();
    PlanNodeStatsEstimate buildSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addSymbolStatistics(ImmutableMap.of(new Symbol("B1"), new SymbolStatsEstimate(0, 100, 0, 640000d * 10000, 10))).build();
    PlanNodeStatsEstimate buildSideSourceStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addSymbolStatistics(ImmutableMap.of(new Symbol("B1"), new SymbolStatsEstimate(0, 100, 0, 64, 10))).build();
    // build side exceeds AUTOMATIC_RESTRICTED limit but source plan nodes are small
    // therefore replicated distribution type is chosen
    assertDetermineSemiJoinDistributionType().setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.AUTOMATIC.name()).setSystemProperty(JOIN_MAX_BROADCAST_TABLE_SIZE, "100MB").overrideStats("valuesA", probeSideStatsEstimate).overrideStats("filterB", buildSideStatsEstimate).overrideStats("valuesB", buildSideSourceStatsEstimate).on(p -> {
        Symbol a1 = p.symbol("A1", symbolType);
        Symbol b1 = p.symbol("B1", symbolType);
        return p.semiJoin(p.values(new PlanNodeId("valuesA"), aRows, a1), p.filter(new PlanNodeId("filterB"), TRUE_LITERAL, p.values(new PlanNodeId("valuesB"), bRows, b1)), a1, b1, p.symbol("output"), Optional.empty(), Optional.empty(), Optional.empty());
    }).matches(semiJoin("A1", "B1", "output", Optional.of(REPLICATED), values(ImmutableMap.of("A1", 0)), filter("true", values(ImmutableMap.of("B1", 0)))));
}
Also used : PlanMatchPattern.semiJoin(io.trino.sql.planner.assertions.PlanMatchPattern.semiJoin) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) Test(org.testng.annotations.Test) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) PARTITIONED(io.trino.sql.planner.plan.SemiJoinNode.DistributionType.PARTITIONED) RuleAssert(io.trino.sql.planner.iterative.rule.test.RuleAssert) PlanBuilder.expressions(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expressions) ImmutableList(com.google.common.collect.ImmutableList) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) JOIN_MAX_BROADCAST_TABLE_SIZE(io.trino.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE) TaskCountEstimator(io.trino.cost.TaskCountEstimator) Symbol(io.trino.sql.planner.Symbol) AfterClass(org.testng.annotations.AfterClass) SymbolStatsEstimate(io.trino.cost.SymbolStatsEstimate) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) RuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) REPLICATED(io.trino.sql.planner.plan.SemiJoinNode.DistributionType.REPLICATED) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) JoinDistributionType(io.trino.sql.planner.OptimizerConfig.JoinDistributionType) CostComparator(io.trino.cost.CostComparator) BIGINT(io.trino.spi.type.BigintType.BIGINT) JOIN_DISTRIBUTION_TYPE(io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) Optional(java.util.Optional) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) JoinDistributionType(io.trino.sql.planner.OptimizerConfig.JoinDistributionType) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) Symbol(io.trino.sql.planner.Symbol) SymbolStatsEstimate(io.trino.cost.SymbolStatsEstimate) Test(org.testng.annotations.Test)

Example 7 with PlanNodeStatsEstimate

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

the class TestMemo method testEvictStatsOnReplace.

@Test
public void testEvictStatsOnReplace() {
    PlanNode y = node();
    PlanNode x = node(y);
    Memo memo = new Memo(idAllocator, x);
    int xGroup = memo.getRootGroup();
    int yGroup = getChildGroup(memo, memo.getRootGroup());
    PlanNodeStatsEstimate xStats = PlanNodeStatsEstimate.builder().setOutputRowCount(42).build();
    PlanNodeStatsEstimate yStats = PlanNodeStatsEstimate.builder().setOutputRowCount(55).build();
    memo.storeStats(yGroup, yStats);
    memo.storeStats(xGroup, xStats);
    assertEquals(memo.getStats(yGroup), Optional.of(yStats));
    assertEquals(memo.getStats(xGroup), Optional.of(xStats));
    memo.replace(yGroup, node(), "rule");
    assertEquals(memo.getStats(yGroup), Optional.empty());
    assertEquals(memo.getStats(xGroup), Optional.empty());
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) Test(org.testng.annotations.Test)

Example 8 with PlanNodeStatsEstimate

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

the class TestApplyPreferredTableWriterPartitioning method testThresholdWithNullFraction.

@Test
public void testThresholdWithNullFraction() {
    // Null value in partition column should increase the number of partitions by 1
    PlanNodeStatsEstimate stats = PlanNodeStatsEstimate.builder().addSymbolStatistics(ImmutableMap.of(new Symbol("col_one"), new SymbolStatsEstimate(0, 0, .5, 0, 49))).build();
    assertPreferredPartitioning(new PartitioningScheme(Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.of(new Symbol("col_one"))), ImmutableList.of(new Symbol("col_one")))).withSession(SESSION_WITH_PREFERRED_PARTITIONING_DEFAULT_THRESHOLD).overrideStats(NODE_ID, stats).matches(SUCCESSFUL_MATCH);
}
Also used : PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) Symbol(io.trino.sql.planner.Symbol) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) SymbolStatsEstimate(io.trino.cost.SymbolStatsEstimate) Test(org.testng.annotations.Test)

Example 9 with PlanNodeStatsEstimate

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

the class TestApplyPreferredTableWriterPartitioning method testThresholdWithMultiplePartitions.

@Test
public void testThresholdWithMultiplePartitions() {
    PlanNodeStatsEstimate stats = PlanNodeStatsEstimate.builder().addSymbolStatistics(ImmutableMap.of(new Symbol("col_one"), new SymbolStatsEstimate(0, 0, 0, 0, 5))).addSymbolStatistics(ImmutableMap.of(new Symbol("col_two"), new SymbolStatsEstimate(0, 0, 0, 0, 10))).build();
    assertPreferredPartitioning(new PartitioningScheme(Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.of(new Symbol("col_one"), new Symbol("col_two"))), ImmutableList.of(new Symbol("col_one"), new Symbol("col_two")))).withSession(SESSION_WITH_PREFERRED_PARTITIONING_DEFAULT_THRESHOLD).overrideStats(NODE_ID, stats).matches(SUCCESSFUL_MATCH);
}
Also used : PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) Symbol(io.trino.sql.planner.Symbol) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) SymbolStatsEstimate(io.trino.cost.SymbolStatsEstimate) Test(org.testng.annotations.Test)

Example 10 with PlanNodeStatsEstimate

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

PlanNodeStatsEstimate (io.trino.cost.PlanNodeStatsEstimate)18 Symbol (io.trino.sql.planner.Symbol)13 ImmutableMap (com.google.common.collect.ImmutableMap)11 SymbolStatsEstimate (io.trino.cost.SymbolStatsEstimate)11 Optional (java.util.Optional)11 Test (org.testng.annotations.Test)11 ImmutableList (com.google.common.collect.ImmutableList)10 JoinDistributionType (io.trino.sql.planner.OptimizerConfig.JoinDistributionType)9 JOIN_DISTRIBUTION_TYPE (io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE)8 JOIN_MAX_BROADCAST_TABLE_SIZE (io.trino.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE)8 CostComparator (io.trino.cost.CostComparator)8 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)8 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)8 RuleAssert (io.trino.sql.planner.iterative.rule.test.RuleAssert)8 RuleTester (io.trino.sql.planner.iterative.rule.test.RuleTester)8 RuleTester.defaultRuleTester (io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester)8 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)8 AfterClass (org.testng.annotations.AfterClass)8 BeforeClass (org.testng.annotations.BeforeClass)8 PlanMatchPattern.equiJoinClause (io.trino.sql.planner.assertions.PlanMatchPattern.equiJoinClause)6