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