Search in sources :

Example 26 with TableScanNode

use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.

the class TestCostCalculator method testReplicatedJoin.

@Test
public void testReplicatedJoin() {
    TableScanNode ts1 = tableScan("ts1", "orderkey");
    TableScanNode ts2 = tableScan("ts2", "orderkey_0");
    JoinNode join = join("join", ts1, ts2, JoinNode.DistributionType.REPLICATED, "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(1000 + 6000 + (12000 + 6000 + 10000 + 1000 * (NUMBER_OF_NODES - 1)) * IS_NULL_OVERHEAD).memory(1000 * NUMBER_OF_NODES * IS_NULL_OVERHEAD).network(0);
    assertCostEstimatedExchanges(join, costs, stats).cpu(1000 + 6000 + (12000 + 6000 + 10000 + 1000 * NUMBER_OF_NODES) * IS_NULL_OVERHEAD).memory(1000 * NUMBER_OF_NODES * IS_NULL_OVERHEAD).network(1000 * NUMBER_OF_NODES * IS_NULL_OVERHEAD);
    assertCostSingleStageFragmentedPlan(join, costs, stats, types).cpu(1000 + 6000 + (12000 + 6000 + 10000 + 1000 * (NUMBER_OF_NODES - 1)) * IS_NULL_OVERHEAD).memory(1000 * NUMBER_OF_NODES * 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 27 with TableScanNode

use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.

the class TestCostCalculator method tableScan.

private TableScanNode tableScan(String id, List<VariableReferenceExpression> variables) {
    ImmutableMap.Builder<VariableReferenceExpression, ColumnHandle> assignments = ImmutableMap.builder();
    for (VariableReferenceExpression variable : variables) {
        assignments.put(variable, new TpchColumnHandle("orderkey", BIGINT));
    }
    TpchTableHandle tableHandle = new TpchTableHandle("orders", 1.0);
    return new TableScanNode(Optional.empty(), new PlanNodeId(id), new TableHandle(new ConnectorId("tpch"), tableHandle, TpchTransactionHandle.INSTANCE, Optional.of(new TpchTableLayoutHandle(tableHandle, TupleDomain.all()))), variables, assignments.build(), TupleDomain.all(), TupleDomain.all());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableLayoutHandle(com.facebook.presto.tpch.TpchTableLayoutHandle) ImmutableMap(com.google.common.collect.ImmutableMap) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 28 with TableScanNode

use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.

the class TestCostCalculator method testAggregation.

@Test
public void testAggregation() {
    TableScanNode tableScan = tableScan("ts", "orderkey");
    AggregationNode aggregation = aggregation("agg", tableScan);
    Map<String, PlanCostEstimate> costs = ImmutableMap.of("ts", cpuCost(6000));
    Map<String, PlanNodeStatsEstimate> stats = ImmutableMap.of("ts", statsEstimate(tableScan, 6000), "agg", statsEstimate(aggregation, 13));
    Map<String, Type> types = ImmutableMap.of("orderkey", BIGINT, "count", BIGINT);
    assertCost(aggregation, costs, stats).cpu(6000 * IS_NULL_OVERHEAD + 6000).memory(13 * IS_NULL_OVERHEAD).network(0);
    assertCostEstimatedExchanges(aggregation, costs, stats).cpu((6000 + 6000 + 6000) * IS_NULL_OVERHEAD + 6000).memory(13 * IS_NULL_OVERHEAD).network(6000 * IS_NULL_OVERHEAD);
    assertCostSingleStageFragmentedPlan(aggregation, costs, stats, types).cpu(6000 + 6000 * IS_NULL_OVERHEAD).memory(13 * IS_NULL_OVERHEAD).network(0 * IS_NULL_OVERHEAD);
    assertCostHasUnknownComponentsForUnknownStats(aggregation);
}
Also used : Type(com.facebook.presto.common.type.Type) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) Test(org.testng.annotations.Test)

Example 29 with TableScanNode

use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.

the class TestCostCalculator method testReplicatedJoinWithExchange.

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

Example 30 with TableScanNode

use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.

the class PickTableLayout method pushPredicateIntoTableScan.

/**
 * For RowExpression {@param predicate}
 */
private static PlanNode pushPredicateIntoTableScan(TableScanNode node, RowExpression predicate, boolean pruneWithPredicateExpression, Session session, PlanNodeIdAllocator idAllocator, Metadata metadata, DomainTranslator domainTranslator) {
    // don't include non-deterministic predicates
    LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata.getFunctionAndTypeManager()), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    RowExpression deterministicPredicate = logicalRowExpressions.filterDeterministicConjuncts(predicate);
    DomainTranslator.ExtractionResult<VariableReferenceExpression> decomposedPredicate = domainTranslator.fromPredicate(session.toConnectorSession(), deterministicPredicate, BASIC_COLUMN_EXTRACTOR);
    TupleDomain<ColumnHandle> newDomain = decomposedPredicate.getTupleDomain().transform(variableName -> node.getAssignments().get(variableName)).intersect(node.getEnforcedConstraint());
    Map<ColumnHandle, VariableReferenceExpression> assignments = ImmutableBiMap.copyOf(node.getAssignments()).inverse();
    Constraint<ColumnHandle> constraint;
    if (pruneWithPredicateExpression) {
        LayoutConstraintEvaluatorForRowExpression evaluator = new LayoutConstraintEvaluatorForRowExpression(metadata, session, node.getAssignments(), logicalRowExpressions.combineConjuncts(deterministicPredicate, // which would be expensive to evaluate in the call to isCandidate below.
        domainTranslator.toPredicate(newDomain.simplify().transform(column -> assignments.getOrDefault(column, null)))));
        constraint = new Constraint<>(newDomain, evaluator::isCandidate);
    } else {
        // Currently, invoking the expression interpreter is very expensive.
        // TODO invoke the interpreter unconditionally when the interpreter becomes cheap enough.
        constraint = new Constraint<>(newDomain);
    }
    if (constraint.getSummary().isNone()) {
        return new ValuesNode(node.getSourceLocation(), idAllocator.getNextId(), node.getOutputVariables(), ImmutableList.of());
    }
    // Layouts will be returned in order of the connector's preference
    TableLayoutResult layout = metadata.getLayout(session, node.getTable(), constraint, Optional.of(node.getOutputVariables().stream().map(variable -> node.getAssignments().get(variable)).collect(toImmutableSet())));
    if (layout.getLayout().getPredicate().isNone()) {
        return new ValuesNode(node.getSourceLocation(), idAllocator.getNextId(), node.getOutputVariables(), ImmutableList.of());
    }
    TableScanNode tableScan = new TableScanNode(node.getSourceLocation(), node.getId(), layout.getLayout().getNewTableHandle(), node.getOutputVariables(), node.getAssignments(), layout.getLayout().getPredicate(), computeEnforced(newDomain, layout.getUnenforcedConstraint()));
    // The order of the arguments to combineConjuncts matters:
    // * Unenforced constraints go first because they can only be simple column references,
    // which are not prone to logic errors such as out-of-bound access, div-by-zero, etc.
    // * Conjuncts in non-deterministic expressions and non-TupleDomain-expressible expressions should
    // retain their original (maybe intermixed) order from the input predicate. However, this is not implemented yet.
    // * Short of implementing the previous bullet point, the current order of non-deterministic expressions
    // and non-TupleDomain-expressible expressions should be retained. Changing the order can lead
    // to failures of previously successful queries.
    RowExpression resultingPredicate = logicalRowExpressions.combineConjuncts(domainTranslator.toPredicate(layout.getUnenforcedConstraint().transform(assignments::get)), logicalRowExpressions.filterNonDeterministicConjuncts(predicate), decomposedPredicate.getRemainingExpression());
    if (!TRUE_CONSTANT.equals(resultingPredicate)) {
        return new FilterNode(node.getSourceLocation(), idAllocator.getNextId(), tableScan, resultingPredicate);
    }
    return tableScan;
}
Also used : RowExpressionDomainTranslator(com.facebook.presto.sql.relational.RowExpressionDomainTranslator) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Pattern(com.facebook.presto.matching.Pattern) TryFunction(com.facebook.presto.operator.scalar.TryFunction) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Capture(com.facebook.presto.matching.Capture) Map(java.util.Map) RowExpressionInterpreter(com.facebook.presto.sql.planner.RowExpressionInterpreter) ImmutableSet(com.google.common.collect.ImmutableSet) NullableValue(com.facebook.presto.common.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) TableLayoutResult.computeEnforced(com.facebook.presto.metadata.TableLayoutResult.computeEnforced) DomainTranslator(com.facebook.presto.spi.relation.DomainTranslator) Set(java.util.Set) TRUE_CONSTANT(com.facebook.presto.expressions.LogicalRowExpressions.TRUE_CONSTANT) Objects(java.util.Objects) Capture.newCapture(com.facebook.presto.matching.Capture.newCapture) Optional(java.util.Optional) TableLayoutResult(com.facebook.presto.metadata.TableLayoutResult) Captures(com.facebook.presto.matching.Captures) RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) Function(java.util.function.Function) Patterns.filter(com.facebook.presto.sql.planner.plan.Patterns.filter) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) FilterNode(com.facebook.presto.spi.plan.FilterNode) SystemSessionProperties.isNewOptimizerEnabled(com.facebook.presto.SystemSessionProperties.isNewOptimizerEnabled) ImmutableList(com.google.common.collect.ImmutableList) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) BASIC_COLUMN_EXTRACTOR(com.facebook.presto.spi.relation.DomainTranslator.BASIC_COLUMN_EXTRACTOR) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) TableHandle(com.facebook.presto.spi.TableHandle) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) VariablesExtractor(com.facebook.presto.sql.planner.VariablesExtractor) RowExpression(com.facebook.presto.spi.relation.RowExpression) VariableResolver(com.facebook.presto.sql.planner.VariableResolver) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) Session(com.facebook.presto.Session) Rule(com.facebook.presto.sql.planner.iterative.Rule) Constraint(com.facebook.presto.spi.Constraint) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) PreconditionRules.checkRulesAreFiredBeforeAddExchangesRule(com.facebook.presto.sql.planner.iterative.rule.PreconditionRules.checkRulesAreFiredBeforeAddExchangesRule) OPTIMIZED(com.facebook.presto.spi.relation.ExpressionOptimizer.Level.OPTIMIZED) Patterns.source(com.facebook.presto.sql.planner.plan.Patterns.source) PlanNode(com.facebook.presto.spi.plan.PlanNode) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) Sets.intersection(com.google.common.collect.Sets.intersection) Patterns.tableScan(com.facebook.presto.sql.planner.plan.Patterns.tableScan) Metadata(com.facebook.presto.metadata.Metadata) RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) FilterNode(com.facebook.presto.spi.plan.FilterNode) RowExpression(com.facebook.presto.spi.relation.RowExpression) TableLayoutResult(com.facebook.presto.metadata.TableLayoutResult) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) RowExpressionDomainTranslator(com.facebook.presto.sql.relational.RowExpressionDomainTranslator) DomainTranslator(com.facebook.presto.spi.relation.DomainTranslator)

Aggregations

TableScanNode (com.facebook.presto.spi.plan.TableScanNode)60 Test (org.testng.annotations.Test)37 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)35 PlanNode (com.facebook.presto.spi.plan.PlanNode)29 ColumnHandle (com.facebook.presto.spi.ColumnHandle)25 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)21 ImmutableList (com.google.common.collect.ImmutableList)18 TableHandle (com.facebook.presto.spi.TableHandle)16 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)16 RowExpression (com.facebook.presto.spi.relation.RowExpression)15 ImmutableMap (com.google.common.collect.ImmutableMap)15 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)14 Optional (java.util.Optional)13 Type (com.facebook.presto.common.type.Type)12 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)12 SemiJoinNode (com.facebook.presto.sql.planner.plan.SemiJoinNode)12 FilterNode (com.facebook.presto.spi.plan.FilterNode)11 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)10 Metadata (com.facebook.presto.metadata.Metadata)10 ImmutableSet (com.google.common.collect.ImmutableSet)10