Search in sources :

Example 26 with JoinNode

use of com.facebook.presto.sql.planner.plan.JoinNode in project presto by prestodb.

the class TestCostCalculator method testMemoryCostJoinAboveJoin.

@Test
public void testMemoryCostJoinAboveJoin() {
    // join
    // /   \
    // ts1    join23
    // /    \
    // ts2     ts3
    TableScanNode ts1 = tableScan("ts1", "key1");
    TableScanNode ts2 = tableScan("ts2", "key2");
    TableScanNode ts3 = tableScan("ts3", "key3");
    JoinNode join23 = join("join23", ts2, ts3, JoinNode.DistributionType.PARTITIONED, "key2", "key3");
    JoinNode join = join("join", ts1, join23, JoinNode.DistributionType.PARTITIONED, "key1", "key2");
    Map<String, PlanCostEstimate> costs = ImmutableMap.of("ts1", new PlanCostEstimate(0, 128, 128, 0), "ts2", new PlanCostEstimate(0, 64, 64, 0), "ts3", new PlanCostEstimate(0, 32, 32, 0));
    Map<String, PlanNodeStatsEstimate> stats = ImmutableMap.of("join", statsEstimate(join, 10_000), "join23", statsEstimate(join23, 2_000), "ts1", statsEstimate(ts1, 10_000), "ts2", statsEstimate(ts2, 1_000), "ts3", statsEstimate(ts3, 100));
    Map<String, Type> types = ImmutableMap.of("key1", BIGINT, "key2", BIGINT, "key3", BIGINT);
    assertCost(join23, costs, stats).memory(// join23 memory footprint
    100 * IS_NULL_OVERHEAD + 64 + // ts2, ts3 memory footprint
    32).memoryWhenOutputting(// join23 memory footprint
    100 * IS_NULL_OVERHEAD + // ts2 memory footprint
    64);
    assertCost(join, costs, stats).memory(// join memory footprint
    2000 * IS_NULL_OVERHEAD + 100 * IS_NULL_OVERHEAD + // join23 total memory when outputting
    64 + // ts1 memory footprint
    128).memoryWhenOutputting(// join memory footprint
    2000 * IS_NULL_OVERHEAD + // ts1 memory footprint
    128);
    assertCostEstimatedExchanges(join23, costs, stats).memory(// join23 memory footprint
    100 * IS_NULL_OVERHEAD + 64 + // ts2, ts3 memory footprint
    32).memoryWhenOutputting(// join23 memory footprint
    100 * IS_NULL_OVERHEAD + // ts2 memory footprint
    64);
    assertCostEstimatedExchanges(join, costs, stats).memory(// join memory footprint
    2000 * IS_NULL_OVERHEAD + 100 * IS_NULL_OVERHEAD + // join23 total memory when outputting
    64 + // ts1 memory footprint
    128).memoryWhenOutputting(// join memory footprint
    2000 * IS_NULL_OVERHEAD + // ts1 memory footprint
    128);
    assertCostSingleStageFragmentedPlan(join23, costs, stats, types).memory(// join23 memory footprint
    100 * IS_NULL_OVERHEAD + 64 + // ts2, ts3 memory footprint
    32).memoryWhenOutputting(// join23 memory footprint
    100 * IS_NULL_OVERHEAD + // ts2 memory footprint
    64);
    assertCostSingleStageFragmentedPlan(join, costs, stats, types).memory(// join memory footprint
    2000 * IS_NULL_OVERHEAD + 100 * IS_NULL_OVERHEAD + // join23 total memory when outputting
    64 + // ts1 memory footprint
    128).memoryWhenOutputting(// join memory footprint
    2000 * IS_NULL_OVERHEAD + // ts1 memory footprint
    128);
}
Also used : Type(com.facebook.presto.common.type.Type) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Test(org.testng.annotations.Test)

Example 27 with JoinNode

use of com.facebook.presto.sql.planner.plan.JoinNode in project presto by prestodb.

the class TestCostCalculator method testRepartitionedJoin.

@Test
public void testRepartitionedJoin() {
    TableScanNode ts1 = tableScan("ts1", "orderkey");
    TableScanNode ts2 = tableScan("ts2", "orderkey_0");
    JoinNode join = join("join", ts1, ts2, JoinNode.DistributionType.PARTITIONED, "orderkey", "orderkey_0");
    Map<String, PlanCostEstimate> costs = ImmutableMap.of("ts1", cpuCost(6000), "ts2", cpuCost(1000));
    Map<String, PlanNodeStatsEstimate> stats = ImmutableMap.of("join", statsEstimate(join, 12000), "ts1", statsEstimate(ts1, 6000), "ts2", statsEstimate(ts2, 1000));
    Map<String, Type> types = ImmutableMap.of("orderkey", BIGINT, "orderkey_0", BIGINT);
    assertCost(join, costs, stats).cpu(6000 + 1000 + (12000 + 6000 + 1000) * IS_NULL_OVERHEAD).memory(1000 * IS_NULL_OVERHEAD).network(0);
    assertCostEstimatedExchanges(join, costs, stats).cpu(6000 + 1000 + (12000 + 6000 + 1000 + 6000 + 1000 + 1000) * IS_NULL_OVERHEAD).memory(1000 * IS_NULL_OVERHEAD).network((6000 + 1000) * IS_NULL_OVERHEAD);
    assertCostSingleStageFragmentedPlan(join, costs, stats, types).cpu(6000 + 1000 + (12000 + 6000 + 1000) * IS_NULL_OVERHEAD).memory(1000 * IS_NULL_OVERHEAD).network(0);
    assertCostHasUnknownComponentsForUnknownStats(join);
}
Also used : Type(com.facebook.presto.common.type.Type) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Test(org.testng.annotations.Test)

Example 28 with JoinNode

use of com.facebook.presto.sql.planner.plan.JoinNode in project presto by prestodb.

the class TestCostCalculator method testRepartitionedJoinWithExchange.

@Test
public void testRepartitionedJoinWithExchange() {
    TableScanNode ts1 = tableScan("ts1", "orderkey");
    TableScanNode ts2 = tableScan("ts2", "orderkey_0");
    PlanNode p1 = project("p1", ts1, variable("orderkey_1", BIGINT), new SymbolReference("orderkey"));
    ExchangeNode remoteExchange1 = systemPartitionedExchange(new PlanNodeId("re1"), REMOTE_STREAMING, p1, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "orderkey_1", BIGINT)), Optional.empty());
    ExchangeNode remoteExchange2 = systemPartitionedExchange(new PlanNodeId("re2"), REMOTE_STREAMING, ts2, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "orderkey_0", BIGINT)), Optional.empty());
    ExchangeNode localExchange = systemPartitionedExchange(new PlanNodeId("le"), LOCAL, remoteExchange2, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "orderkey_0", BIGINT)), Optional.empty());
    JoinNode join = join("join", remoteExchange1, localExchange, JoinNode.DistributionType.PARTITIONED, "orderkey_1", "orderkey_0");
    Map<String, PlanNodeStatsEstimate> stats = ImmutableMap.<String, PlanNodeStatsEstimate>builder().put("join", statsEstimate(join, 12000)).put("re1", statsEstimate(remoteExchange1, 10000)).put("re2", statsEstimate(remoteExchange2, 10000)).put("le", statsEstimate(localExchange, 6000)).put("p1", statsEstimate(p1, 6000)).put("ts1", statsEstimate(ts1, 6000)).put("ts2", statsEstimate(ts2, 1000)).build();
    Map<String, Type> types = ImmutableMap.of("orderkey", BIGINT, "orderkey_1", BIGINT, "orderkey_0", BIGINT);
    assertFragmentedEqualsUnfragmented(join, stats, types);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) PlanNode(com.facebook.presto.spi.plan.PlanNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Test(org.testng.annotations.Test)

Example 29 with JoinNode

use of com.facebook.presto.sql.planner.plan.JoinNode in project presto by prestodb.

the class TestCostCalculator method join.

/**
 * EquiJoinClause is created from symbols in form of:
 * symbol[0] = symbol[1] AND symbol[2] = symbol[3] AND ...
 */
private JoinNode join(String planNodeId, PlanNode left, PlanNode right, JoinNode.DistributionType distributionType, String... symbols) {
    checkArgument(symbols.length % 2 == 0);
    ImmutableList.Builder<JoinNode.EquiJoinClause> criteria = ImmutableList.builder();
    for (int i = 0; i < symbols.length; i += 2) {
        criteria.add(new JoinNode.EquiJoinClause(new VariableReferenceExpression(Optional.empty(), symbols[i], BIGINT), new VariableReferenceExpression(Optional.empty(), symbols[i + 1], BIGINT)));
    }
    return new JoinNode(Optional.empty(), new PlanNodeId(planNodeId), JoinNode.Type.INNER, left, right, criteria.build(), ImmutableList.<VariableReferenceExpression>builder().addAll(left.getOutputVariables()).addAll(right.getOutputVariables()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(distributionType), ImmutableMap.of());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression)

Example 30 with JoinNode

use of com.facebook.presto.sql.planner.plan.JoinNode in project presto by prestodb.

the class TestVerifyNoOriginalExpression method validateJoin.

private void validateJoin(RowExpression rowExpressionPredicate, Expression expressionPredicate, boolean ifRowExpression) {
    ImmutableMap<VariableReferenceExpression, RowExpression> map = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, VARIABLE_REFERENCE_EXPRESSION);
    ProjectNode projectNode = builder.project(new Assignments(map), valuesNode);
    JoinNode joinNode;
    if (ifRowExpression) {
        joinNode = builder.join(JoinNode.Type.INNER, projectNode, projectNode, rowExpressionPredicate);
    } else {
        joinNode = builder.join(JoinNode.Type.INNER, projectNode, projectNode, castToRowExpression(expressionPredicate));
    }
    testValidation(joinNode);
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) SpatialJoinNode(com.facebook.presto.sql.planner.plan.SpatialJoinNode) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Assignments(com.facebook.presto.spi.plan.Assignments) RowExpression(com.facebook.presto.spi.relation.RowExpression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) ProjectNode(com.facebook.presto.spi.plan.ProjectNode)

Aggregations

JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)49 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)36 Test (org.testng.annotations.Test)24 PlanNode (com.facebook.presto.spi.plan.PlanNode)23 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)15 RowExpression (com.facebook.presto.spi.relation.RowExpression)15 ImmutableList (com.google.common.collect.ImmutableList)13 FilterNode (com.facebook.presto.spi.plan.FilterNode)11 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)9 SemiJoinNode (com.facebook.presto.sql.planner.plan.SemiJoinNode)9 Type (com.facebook.presto.common.type.Type)8 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)8 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)8 Session (com.facebook.presto.Session)6 Metadata (com.facebook.presto.metadata.Metadata)6 Assignments (com.facebook.presto.spi.plan.Assignments)6 BasePlanTest (com.facebook.presto.sql.planner.assertions.BasePlanTest)6 MultiJoinNode (com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode)6 MultiJoinNode.toMultiJoinNode (com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode)6