use of io.trino.cost.PlanNodeStatsEstimate in project trino by trinodb.
the class TestDetermineSemiJoinDistributionType method testReplicatesWhenSourceIsSmall.
@Test
public void testReplicatesWhenSourceIsSmall() {
// variable width so that average row size is respected
Type symbolType = createUnboundedVarcharType();
int aRows = 10_000;
int bRows = 10;
PlanNodeStatsEstimate probeSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addSymbolStatistics(ImmutableMap.of(new Symbol("A1"), new SymbolStatsEstimate(0, 100, 0, 640000d * 10000, 10))).build();
PlanNodeStatsEstimate buildSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addSymbolStatistics(ImmutableMap.of(new Symbol("B1"), new SymbolStatsEstimate(0, 100, 0, 640000d * 10000, 10))).build();
PlanNodeStatsEstimate buildSideSourceStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addSymbolStatistics(ImmutableMap.of(new Symbol("B1"), new SymbolStatsEstimate(0, 100, 0, 64, 10))).build();
// build side exceeds AUTOMATIC_RESTRICTED limit but source plan nodes are small
// therefore replicated distribution type is chosen
assertDetermineSemiJoinDistributionType().setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.AUTOMATIC.name()).setSystemProperty(JOIN_MAX_BROADCAST_TABLE_SIZE, "100MB").overrideStats("valuesA", probeSideStatsEstimate).overrideStats("filterB", buildSideStatsEstimate).overrideStats("valuesB", buildSideSourceStatsEstimate).on(p -> {
Symbol a1 = p.symbol("A1", symbolType);
Symbol b1 = p.symbol("B1", symbolType);
return p.semiJoin(p.values(new PlanNodeId("valuesA"), aRows, a1), p.filter(new PlanNodeId("filterB"), TRUE_LITERAL, p.values(new PlanNodeId("valuesB"), bRows, b1)), a1, b1, p.symbol("output"), Optional.empty(), Optional.empty(), Optional.empty());
}).matches(semiJoin("A1", "B1", "output", Optional.of(REPLICATED), values(ImmutableMap.of("A1", 0)), filter("true", values(ImmutableMap.of("B1", 0)))));
}
use of io.trino.cost.PlanNodeStatsEstimate in project trino by trinodb.
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 io.trino.cost.PlanNodeStatsEstimate in project trino by trinodb.
the class TestApplyPreferredTableWriterPartitioning method testThresholdWithNullFraction.
@Test
public void testThresholdWithNullFraction() {
// Null value in partition column should increase the number of partitions by 1
PlanNodeStatsEstimate stats = PlanNodeStatsEstimate.builder().addSymbolStatistics(ImmutableMap.of(new Symbol("col_one"), new SymbolStatsEstimate(0, 0, .5, 0, 49))).build();
assertPreferredPartitioning(new PartitioningScheme(Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.of(new Symbol("col_one"))), ImmutableList.of(new Symbol("col_one")))).withSession(SESSION_WITH_PREFERRED_PARTITIONING_DEFAULT_THRESHOLD).overrideStats(NODE_ID, stats).matches(SUCCESSFUL_MATCH);
}
use of io.trino.cost.PlanNodeStatsEstimate in project trino by trinodb.
the class TestApplyPreferredTableWriterPartitioning method testThresholdWithMultiplePartitions.
@Test
public void testThresholdWithMultiplePartitions() {
PlanNodeStatsEstimate stats = PlanNodeStatsEstimate.builder().addSymbolStatistics(ImmutableMap.of(new Symbol("col_one"), new SymbolStatsEstimate(0, 0, 0, 0, 5))).addSymbolStatistics(ImmutableMap.of(new Symbol("col_two"), new SymbolStatsEstimate(0, 0, 0, 0, 10))).build();
assertPreferredPartitioning(new PartitioningScheme(Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.of(new Symbol("col_one"), new Symbol("col_two"))), ImmutableList.of(new Symbol("col_one"), new Symbol("col_two")))).withSession(SESSION_WITH_PREFERRED_PARTITIONING_DEFAULT_THRESHOLD).overrideStats(NODE_ID, stats).matches(SUCCESSFUL_MATCH);
}
use of io.trino.cost.PlanNodeStatsEstimate in project trino by trinodb.
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);
List<Symbol> outputSymbols = node.getOutputs().stream().map(TypedSymbol::getSymbol).collect(toList());
output.append(format("{rows: %s (%s), cpu: %s, memory: %s, network: %s}", formatAsLong(stats.getOutputRowCount()), formatAsDataSize(stats.getOutputSizeInBytes(outputSymbols, plan.getTypes())), formatAsCpuCost(cost.getCpuCost()), formatAsDataSize(cost.getMaxMemory()), formatAsDataSize(cost.getNetworkCost())));
if (i < estimateCount - 1) {
output.append("/");
}
}
output.append("\n");
return output.toString();
}
Aggregations