Search in sources :

Example 6 with VariableStatsEstimate

use of com.facebook.presto.cost.VariableStatsEstimate 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 7 with VariableStatsEstimate

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

the class TestPushPartialAggregationThroughExchange method testPartialAggregationEnabledWhenNotConfident.

@Test
public void testPartialAggregationEnabledWhenNotConfident() {
    tester().assertThat(new PushPartialAggregationThroughExchange(getFunctionManager())).setSystemProperty(PARTIAL_AGGREGATION_STRATEGY, "AUTOMATIC").on(p -> {
        VariableReferenceExpression a = p.variable("a", DOUBLE);
        VariableReferenceExpression b = p.variable("b", DOUBLE);
        return p.aggregation(ab -> ab.source(p.exchange(e -> e.addSource(p.values(new PlanNodeId("values"), a, b)).addInputsSet(a, b).singleDistributionPartitioningScheme(a, b))).addAggregation(p.variable("SUM", DOUBLE), expression("SUM(a)"), ImmutableList.of(DOUBLE)).singleGroupingSet(b).step(PARTIAL));
    }).overrideStats("values", PlanNodeStatsEstimate.builder().setOutputRowCount(1000).addVariableStatistics(variable("b", DOUBLE), new VariableStatsEstimate(0, 100, 0, 8, 800)).setConfident(false).build()).matches(exchange(project(aggregation(ImmutableMap.of("SUM", functionCall("sum", ImmutableList.of("a"))), PARTIAL, values("a", "b")))));
}
Also used : PARTIAL(com.facebook.presto.spi.plan.AggregationNode.Step.PARTIAL) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) PlanMatchPattern.exchange(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.exchange) SINGLE(com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) Expressions.variable(com.facebook.presto.sql.relational.Expressions.variable) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) PlanBuilder.expression(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.expression) PlanMatchPattern.functionCall(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.functionCall) PARTIAL_AGGREGATION_STRATEGY(com.facebook.presto.SystemSessionProperties.PARTIAL_AGGREGATION_STRATEGY) PlanMatchPattern.aggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Example 8 with VariableStatsEstimate

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

the class TestPushPartialAggregationThroughExchange method testNoPartialAggregationWhenReductionBelowThreshold.

@Test
public void testNoPartialAggregationWhenReductionBelowThreshold() {
    tester().assertThat(new PushPartialAggregationThroughExchange(getFunctionManager())).setSystemProperty(PARTIAL_AGGREGATION_STRATEGY, "AUTOMATIC").on(p -> {
        VariableReferenceExpression a = p.variable("a", DOUBLE);
        VariableReferenceExpression b = p.variable("b", DOUBLE);
        return p.aggregation(ab -> ab.source(p.exchange(e -> e.addSource(p.values(new PlanNodeId("values"), a, b)).addInputsSet(a, b).singleDistributionPartitioningScheme(a, b))).addAggregation(p.variable("SUM", DOUBLE), expression("SUM(a)"), ImmutableList.of(DOUBLE)).singleGroupingSet(b).step(SINGLE));
    }).overrideStats("values", PlanNodeStatsEstimate.builder().setOutputRowCount(1000).addVariableStatistics(variable("b", DOUBLE), new VariableStatsEstimate(0, 100, 0, 8, 800)).setConfident(true).build()).doesNotFire();
}
Also used : PARTIAL(com.facebook.presto.spi.plan.AggregationNode.Step.PARTIAL) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) PlanMatchPattern.exchange(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.exchange) SINGLE(com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) Expressions.variable(com.facebook.presto.sql.relational.Expressions.variable) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) PlanBuilder.expression(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.expression) PlanMatchPattern.functionCall(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.functionCall) PARTIAL_AGGREGATION_STRATEGY(com.facebook.presto.SystemSessionProperties.PARTIAL_AGGREGATION_STRATEGY) PlanMatchPattern.aggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Example 9 with VariableStatsEstimate

use of com.facebook.presto.cost.VariableStatsEstimate in project urban-eureka by errir503.

the class TestReorderJoins method testReorderAndReplicate.

@Test
public void testReorderAndReplicate() {
    int aRows = 10;
    int bRows = 10_000;
    PlanNodeStatsEstimate probeSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addVariableStatistics(ImmutableMap.of(variable("A1", VARCHAR), new VariableStatsEstimate(0, 100, 0, 640000, 10))).build();
    PlanNodeStatsEstimate buildSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addVariableStatistics(ImmutableMap.of(variable("B1", VARCHAR), new VariableStatsEstimate(0, 100, 0, 640000, 10))).build();
    // A table is small enough to be replicated in AUTOMATIC_RESTRICTED mode
    assertReorderJoins().setSystemProperty(JOIN_DISTRIBUTION_TYPE, AUTOMATIC.name()).setSystemProperty(JOIN_REORDERING_STRATEGY, AUTOMATIC.name()).setSystemProperty(JOIN_MAX_BROADCAST_TABLE_SIZE, "10MB").on(p -> {
        VariableReferenceExpression a1 = p.variable("A1", VARCHAR);
        VariableReferenceExpression b1 = p.variable("B1", VARCHAR);
        return p.join(INNER, p.values(new PlanNodeId("valuesA"), aRows, a1), p.values(new PlanNodeId("valuesB"), bRows, b1), ImmutableList.of(new EquiJoinClause(a1, b1)), ImmutableList.of(a1, b1), Optional.empty());
    }).overrideStats("valuesA", probeSideStatsEstimate).overrideStats("valuesB", buildSideStatsEstimate).matches(join(INNER, ImmutableList.of(equiJoinClause("B1", "A1")), Optional.empty(), Optional.of(REPLICATED), values(ImmutableMap.of("B1", 0)), values(ImmutableMap.of("A1", 0))));
}
Also used : JoinReorderingStrategy(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinReorderingStrategy) EquiJoinClause(com.facebook.presto.sql.planner.plan.JoinNode.EquiJoinClause) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) AUTOMATIC(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType.AUTOMATIC) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) PlanMatchPattern.join(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join) 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) PlanMatchPattern.equiJoinClause(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause) EQUAL(com.facebook.presto.common.function.OperatorType.EQUAL) LESS_THAN(com.facebook.presto.common.function.OperatorType.LESS_THAN) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) Expressions.variable(com.facebook.presto.sql.relational.Expressions.variable) RuleAssert(com.facebook.presto.sql.planner.iterative.rule.test.RuleAssert) FunctionAndTypeManager.qualifyObjectName(com.facebook.presto.metadata.FunctionAndTypeManager.qualifyObjectName) RowExpression(com.facebook.presto.spi.relation.RowExpression) 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) BeforeClass(org.testng.annotations.BeforeClass) JOIN_DISTRIBUTION_TYPE(com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) OperatorType(com.facebook.presto.common.function.OperatorType) List(java.util.List) REPLICATED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.REPLICATED) JOIN_REORDERING_STRATEGY(com.facebook.presto.SystemSessionProperties.JOIN_REORDERING_STRATEGY) CostComparator(com.facebook.presto.cost.CostComparator) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) PARTITIONED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) Closeables.closeAllRuntimeException(com.facebook.airlift.testing.Closeables.closeAllRuntimeException) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) BROADCAST(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType.BROADCAST) INNER(com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) EquiJoinClause(com.facebook.presto.sql.planner.plan.JoinNode.EquiJoinClause) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) Test(org.testng.annotations.Test)

Example 10 with VariableStatsEstimate

use of com.facebook.presto.cost.VariableStatsEstimate in project urban-eureka by errir503.

the class TestPushPartialAggregationThroughExchange method testPartialAggregationEnabledWhenNotConfident.

@Test
public void testPartialAggregationEnabledWhenNotConfident() {
    tester().assertThat(new PushPartialAggregationThroughExchange(getFunctionManager())).setSystemProperty(PARTIAL_AGGREGATION_STRATEGY, "AUTOMATIC").on(p -> {
        VariableReferenceExpression a = p.variable("a", DOUBLE);
        VariableReferenceExpression b = p.variable("b", DOUBLE);
        return p.aggregation(ab -> ab.source(p.exchange(e -> e.addSource(p.values(new PlanNodeId("values"), a, b)).addInputsSet(a, b).singleDistributionPartitioningScheme(a, b))).addAggregation(p.variable("SUM", DOUBLE), expression("SUM(a)"), ImmutableList.of(DOUBLE)).singleGroupingSet(b).step(PARTIAL));
    }).overrideStats("values", PlanNodeStatsEstimate.builder().setOutputRowCount(1000).addVariableStatistics(variable("b", DOUBLE), new VariableStatsEstimate(0, 100, 0, 8, 800)).setConfident(false).build()).matches(exchange(project(aggregation(ImmutableMap.of("SUM", functionCall("sum", ImmutableList.of("a"))), PARTIAL, values("a", "b")))));
}
Also used : PARTIAL(com.facebook.presto.spi.plan.AggregationNode.Step.PARTIAL) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) PlanMatchPattern.exchange(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.exchange) SINGLE(com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) Expressions.variable(com.facebook.presto.sql.relational.Expressions.variable) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) PlanBuilder.expression(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.expression) PlanMatchPattern.functionCall(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.functionCall) PARTIAL_AGGREGATION_STRATEGY(com.facebook.presto.SystemSessionProperties.PARTIAL_AGGREGATION_STRATEGY) PlanMatchPattern.aggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Aggregations

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