Search in sources :

Example 1 with PlanNodeStatsEstimate

use of com.facebook.presto.cost.PlanNodeStatsEstimate in project presto by prestodb.

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(com.facebook.presto.spi.plan.PlanNode) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) Test(org.testng.annotations.Test)

Example 2 with PlanNodeStatsEstimate

use of com.facebook.presto.cost.PlanNodeStatsEstimate in project presto by prestodb.

the class TestDetermineSemiJoinDistributionType method testReplicatesWhenNotRestricted.

@Test
public void testReplicatesWhenNotRestricted() {
    int aRows = 10_000;
    int bRows = 10;
    PlanNodeStatsEstimate probeSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "A1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000, 10))).build();
    PlanNodeStatsEstimate buildSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "B1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000, 10))).build();
    // B table is small enough to be replicated in AUTOMATIC_RESTRICTED mode
    assertDetermineSemiJoinDistributionType().setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.AUTOMATIC.name()).setSystemProperty(JOIN_MAX_BROADCAST_TABLE_SIZE, "100MB").overrideStats("valuesA", probeSideStatsEstimate).overrideStats("valuesB", buildSideStatsEstimate).on(p -> p.semiJoin(p.values(new PlanNodeId("valuesA"), aRows, p.variable("A1", BIGINT)), p.values(new PlanNodeId("valuesB"), bRows, p.variable("B1", BIGINT)), p.variable("A1"), p.variable("B1"), p.variable("output"), Optional.empty(), Optional.empty(), Optional.empty())).matches(semiJoin("A1", "B1", "output", Optional.of(REPLICATED), values(ImmutableMap.of("A1", 0)), values(ImmutableMap.of("B1", 0))));
    probeSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "A1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000d * 10000, 10))).build();
    buildSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "B1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000d * 10000, 10))).build();
    // B table exceeds AUTOMATIC_RESTRICTED limit therefore it is partitioned
    assertDetermineSemiJoinDistributionType().setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.AUTOMATIC.name()).setSystemProperty(JOIN_MAX_BROADCAST_TABLE_SIZE, "100MB").overrideStats("valuesA", probeSideStatsEstimate).overrideStats("valuesB", buildSideStatsEstimate).on(p -> p.semiJoin(p.values(new PlanNodeId("valuesA"), aRows, p.variable("A1", BIGINT)), p.values(new PlanNodeId("valuesB"), bRows, p.variable("B1", BIGINT)), p.variable("A1"), p.variable("B1"), p.variable("output"), Optional.empty(), Optional.empty(), Optional.empty())).matches(semiJoin("A1", "B1", "output", Optional.of(PARTITIONED), values(ImmutableMap.of("A1", 0)), values(ImmutableMap.of("B1", 0))));
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) AfterClass(org.testng.annotations.AfterClass) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) ImmutableMap(com.google.common.collect.ImmutableMap) PlanMatchPattern.semiJoin(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.semiJoin) BeforeClass(org.testng.annotations.BeforeClass) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) JOIN_DISTRIBUTION_TYPE(com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) PARTITIONED(com.facebook.presto.sql.planner.plan.SemiJoinNode.DistributionType.PARTITIONED) PlanBuilder.constantExpressions(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.constantExpressions) REPLICATED(com.facebook.presto.sql.planner.plan.SemiJoinNode.DistributionType.REPLICATED) JoinDistributionType(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType) ImmutableList(com.google.common.collect.ImmutableList) JOIN_MAX_BROADCAST_TABLE_SIZE(com.facebook.presto.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE) CostComparator(com.facebook.presto.cost.CostComparator) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) RuleAssert(com.facebook.presto.sql.planner.iterative.rule.test.RuleAssert) TaskCountEstimator(com.facebook.presto.cost.TaskCountEstimator) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) Test(org.testng.annotations.Test)

Example 3 with PlanNodeStatsEstimate

use of com.facebook.presto.cost.PlanNodeStatsEstimate in project presto by prestodb.

the class DetermineSemiJoinDistributionType method canReplicate.

private boolean canReplicate(SemiJoinNode node, Context context) {
    DataSize joinMaxBroadcastTableSize = getJoinMaxBroadcastTableSize(context.getSession());
    PlanNode buildSide = node.getFilteringSource();
    PlanNodeStatsEstimate buildSideStatsEstimate = context.getStatsProvider().getStats(buildSide);
    double buildSideSizeInBytes = buildSideStatsEstimate.getOutputSizeInBytes(buildSide.getOutputVariables());
    return buildSideSizeInBytes <= joinMaxBroadcastTableSize.toBytes();
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) DataSize(io.airlift.units.DataSize)

Example 4 with PlanNodeStatsEstimate

use of com.facebook.presto.cost.PlanNodeStatsEstimate in project presto by prestodb.

the class PushPartialAggregationThroughExchange method partialAggregationNotUseful.

private boolean partialAggregationNotUseful(AggregationNode aggregationNode, ExchangeNode exchangeNode, Context context) {
    StatsProvider stats = context.getStatsProvider();
    PlanNodeStatsEstimate exchangeStats = stats.getStats(exchangeNode);
    PlanNodeStatsEstimate aggregationStats = stats.getStats(aggregationNode);
    double inputBytes = exchangeStats.getOutputSizeInBytes(exchangeNode.getOutputVariables());
    double outputBytes = aggregationStats.getOutputSizeInBytes(aggregationNode.getOutputVariables());
    double byteReductionThreshold = getPartialAggregationByteReductionThreshold(context.getSession());
    return exchangeStats.isConfident() && outputBytes > inputBytes * byteReductionThreshold;
}
Also used : StatsProvider(com.facebook.presto.cost.StatsProvider) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate)

Example 5 with PlanNodeStatsEstimate

use of com.facebook.presto.cost.PlanNodeStatsEstimate in project presto by prestodb.

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);
        output.append(format("{rows: %s (%s), cpu: %s, memory: %s, network: %s}", formatAsLong(stats.getOutputRowCount()), formatEstimateAsDataSize(stats.getOutputSizeInBytes(node.getOutputs())), formatDouble(cost.getCpuCost()), formatDouble(cost.getMaxMemory()), formatDouble(cost.getNetworkCost())));
        if (i < estimateCount - 1) {
            output.append("/");
        }
    }
    output.append("\n");
    return output.toString();
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) PlanCostEstimate(com.facebook.presto.cost.PlanCostEstimate) Strings(com.google.common.base.Strings) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Double.isNaN(java.lang.Double.isNaN) Locale(java.util.Locale) Map(java.util.Map) Optional(java.util.Optional) Double.isFinite(java.lang.Double.isFinite) PlanCostEstimate(com.facebook.presto.cost.PlanCostEstimate) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate)

Aggregations

PlanNodeStatsEstimate (com.facebook.presto.cost.PlanNodeStatsEstimate)11 ImmutableMap (com.google.common.collect.ImmutableMap)6 Optional (java.util.Optional)6 Test (org.testng.annotations.Test)6 JOIN_DISTRIBUTION_TYPE (com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE)5 JOIN_MAX_BROADCAST_TABLE_SIZE (com.facebook.presto.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE)5 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)5 CostComparator (com.facebook.presto.cost.CostComparator)5 VariableStatsEstimate (com.facebook.presto.cost.VariableStatsEstimate)5 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)5 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)5 JoinDistributionType (com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType)5 PlanMatchPattern.values (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values)5 RuleAssert (com.facebook.presto.sql.planner.iterative.rule.test.RuleAssert)5 RuleTester (com.facebook.presto.sql.planner.iterative.rule.test.RuleTester)5 ImmutableList (com.google.common.collect.ImmutableList)5 AfterClass (org.testng.annotations.AfterClass)5 BeforeClass (org.testng.annotations.BeforeClass)5 PlanMatchPattern.equiJoinClause (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause)4 PlanMatchPattern.join (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join)4