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);
}
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());
}
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);
}
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);
}
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;
}
Aggregations