.setOutputRowCount(outputRowsCount) .addSymbolStatistics(node.getRowNumberSymbol(), SymbolStatsEstimate.builder() .setAverageRowSize(BIGINT.getFixedSize()) .build()) .build());
private PlanNodeStatsEstimate normalize(PlanNodeStatsEstimate stats, Optional<Collection<Symbol>> outputSymbols, TypeProvider types) { if (stats.isOutputRowCountUnknown()) { return PlanNodeStatsEstimate.unknown(); } PlanNodeStatsEstimate.Builder normalized = PlanNodeStatsEstimate.buildFrom(stats); Predicate<Symbol> symbolFilter = outputSymbols .map(ImmutableSet::copyOf) .map(set -> (Predicate<Symbol>) set::contains) .orElse(symbol -> true); for (Symbol symbol : stats.getSymbolsWithKnownStatistics()) { if (!symbolFilter.test(symbol)) { normalized.removeSymbolStatistics(symbol); continue; } SymbolStatsEstimate symbolStats = stats.getSymbolStatistics(symbol); SymbolStatsEstimate normalizedSymbolStats = stats.getOutputRowCount() == 0 ? SymbolStatsEstimate.zero() : normalizeSymbolStats(symbol, symbolStats, stats, types); if (normalizedSymbolStats.isUnknown()) { normalized.removeSymbolStatistics(symbol); continue; } if (!Objects.equals(normalizedSymbolStats, symbolStats)) { normalized.addSymbolStatistics(symbol, normalizedSymbolStats); } } return normalized.build(); }
pb.values(pb.symbol("i21", BIGINT), pb.symbol("i22", BIGINT), pb.symbol("i23", BIGINT), pb.symbol("i24", BIGINT), pb.symbol("i25", BIGINT))))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(new Symbol("i11"), SymbolStatsEstimate.builder() .setLowValue(1) .setHighValue(10) .setNullsFraction(0.3) .build()) .addSymbolStatistics(new Symbol("i12"), SymbolStatsEstimate.builder() .setLowValue(0) .setHighValue(3) .setNullsFraction(0) .build()) .addSymbolStatistics(new Symbol("i13"), SymbolStatsEstimate.builder() .setLowValue(10) .setHighValue(15) .setNullsFraction(0.1) .build()) .addSymbolStatistics(new Symbol("i14"), SymbolStatsEstimate.builder() .setLowValue(10) .setHighValue(15) .setNullsFraction(0.1) .build()) .addSymbolStatistics(new Symbol("i15"), SymbolStatsEstimate.builder() .setLowValue(10)
.build(); standardInputStatistics = PlanNodeStatsEstimate.builder() .addSymbolStatistics(new Symbol("u"), uStats) .addSymbolStatistics(new Symbol("w"), wStats) .addSymbolStatistics(new Symbol("x"), xStats) .addSymbolStatistics(new Symbol("y"), yStats) .addSymbolStatistics(new Symbol("z"), zStats) .addSymbolStatistics(new Symbol("leftOpen"), leftOpenStats) .addSymbolStatistics(new Symbol("rightOpen"), rightOpenStats) .addSymbolStatistics(new Symbol("unknownRange"), unknownRangeStats) .addSymbolStatistics(new Symbol("emptyRange"), emptyRangeStats) .addSymbolStatistics(new Symbol("varchar"), varcharStats) .setOutputRowCount(1000.0) .build();
pb.values(pb.symbol("i1"), pb.symbol("i2"), pb.symbol("i3")))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(new Symbol("i1"), SymbolStatsEstimate.builder() .setLowValue(1) .setHighValue(10) .setNullsFraction(0) .build()) .addSymbolStatistics(new Symbol("i2"), SymbolStatsEstimate.builder() .setLowValue(0) .setHighValue(3) .setNullsFraction(0) .build()) .addSymbolStatistics(new Symbol("i3"), SymbolStatsEstimate.builder() .setLowValue(10) .setHighValue(15) .setNullsFraction(0.1) .build()) .build()) .check(check -> check .outputRowsCount(2) pb.values(pb.symbol("i1"), pb.symbol("i2"), pb.symbol("i3")))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(new Symbol("i1"), SymbolStatsEstimate.builder()
.build(); inputStatistics = PlanNodeStatsEstimate.builder() .addSymbolStatistics(u, uStats) .addSymbolStatistics(w, wStats) .addSymbolStatistics(x, xStats) .addSymbolStatistics(y, yStats) .addSymbolStatistics(z, zStats) .addSymbolStatistics(leftOpen, leftOpenStats) .addSymbolStatistics(rightOpen, rightOpenStats) .addSymbolStatistics(unknownRange, unknownRangeStats) .addSymbolStatistics(emptyRange, emptyRangeStats) .addSymbolStatistics(unknown, SymbolStatsEstimate.unknown()) .addSymbolStatistics(fractionalNdv, fractionalNdvStats) .setOutputRowCount(1000.0) .build();
.addSource(pb.values(pb.symbol("i21", BIGINT), pb.symbol("i22", BIGINT), pb.symbol("i23", BIGINT), pb.symbol("i24", BIGINT))))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(new Symbol("i11"), SymbolStatsEstimate.builder() .setLowValue(1) .setHighValue(10) .setNullsFraction(0.3) .build()) .addSymbolStatistics(new Symbol("i12"), SymbolStatsEstimate.builder() .setLowValue(0) .setHighValue(3) .setNullsFraction(0) .build()) .addSymbolStatistics(new Symbol("i13"), SymbolStatsEstimate.builder() .setLowValue(10) .setHighValue(15) .setNullsFraction(0.1) .build()) .addSymbolStatistics(new Symbol("i14"), SymbolStatsEstimate.builder() .setLowValue(10) .setHighValue(15) .setNullsFraction(0.1) .build()) .build()) .withSourceStats(1, PlanNodeStatsEstimate.builder()
.build(); standardInputStatistics = PlanNodeStatsEstimate.builder() .addSymbolStatistics(new Symbol("x"), xStats) .addSymbolStatistics(new Symbol("y"), yStats) .addSymbolStatistics(new Symbol("z"), zStats) .addSymbolStatistics(new Symbol("leftOpen"), leftOpenStats) .addSymbolStatistics(new Symbol("rightOpen"), rightOpenStats) .addSymbolStatistics(new Symbol("unknownRange"), unknownRangeStats) .addSymbolStatistics(new Symbol("emptyRange"), emptyRangeStats) .addSymbolStatistics(new Symbol("mediumVarchar"), mediumVarcharStats) .setOutputRowCount(1000.0) .build();
pb.values(pb.symbol("i1"), pb.symbol("i2"), pb.symbol("i3")))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(new Symbol("i1"), SymbolStatsEstimate.builder() .setLowValue(1) .setHighValue(10) .setNullsFraction(0) .build()) .addSymbolStatistics(new Symbol("i2"), SymbolStatsEstimate.builder() .setLowValue(0) .setHighValue(3) .setNullsFraction(0) .build()) .addSymbolStatistics(new Symbol("i3"), SymbolStatsEstimate.builder() .setLowValue(10) .setHighValue(15) .setNullsFraction(0.1) .build()) .build()) .check(check -> check.outputRowsCountUnknown()); pb.values(pb.symbol("i1"), pb.symbol("i2"), pb.symbol("i3")))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(new Symbol("i1"), SymbolStatsEstimate.builder() .setLowValue(1)
pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(new Symbol("x"), xStats) .addSymbolStatistics(new Symbol("y"), yStats) .build()) .check(check -> check .outputRowsCount(10) pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(new Symbol("x"), xStats) .addSymbolStatistics(new Symbol("y"), yStats) .build()) .check(check -> check .outputRowsCount(5) pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(60) .addSymbolStatistics(new Symbol("x"), xStats) .addSymbolStatistics(new Symbol("y"), yStats) .build()) .check(check -> check .outputRowsCount(60) pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))) .withSourceStats(0, PlanNodeStatsEstimate.builder()
result.setOutputRowCount(outputRowCount); newSymbolStats.setHighValue(supersetSymbolStats.getHighValue()); result.addSymbolStatistics(symbol, newSymbolStats.build()); }); return result.build();
pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(60) .addSymbolStatistics(new Symbol("x"), xStats) .addSymbolStatistics(new Symbol("y"), yStats) .build()) .check(check -> check .outputRowsCount(60) pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(20) .addSymbolStatistics(new Symbol("x"), xStats) .addSymbolStatistics(new Symbol("y"), yStats) .build()) .check(check -> check .outputRowsCount(20) pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(20) .addSymbolStatistics(new Symbol("x"), xStats) .addSymbolStatistics(new Symbol("y"), SymbolStatsEstimate.unknown()) .build()) .check(PlanNodeStatsAssertion::outputRowsCountUnknown);
.check(outputStats -> outputStats.equalTo( PlanNodeStatsEstimate.builder() .setOutputRowCount(3) .addSymbolStatistics( new Symbol("a"), SymbolStatsEstimate.builder() .setDistinctValuesCount(2) .build()) .addSymbolStatistics( new Symbol("b"), SymbolStatsEstimate.builder() .setDistinctValuesCount(1) .build()) .build())); .check(outputStats -> outputStats.equalTo( PlanNodeStatsEstimate.builder() .setOutputRowCount(4) .addSymbolStatistics( new Symbol("v"), SymbolStatsEstimate.builder() .build()));
.source(pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT), pb.symbol("z", BIGINT))))) .withSourceStats(PlanNodeStatsEstimate.builder() .setOutputRowCount(100) .addSymbolStatistics(new Symbol("x"), SymbolStatsEstimate.builder() .setLowValue(1) .setHighValue(10) .setNullsFraction(0.3) .build()) .addSymbolStatistics(new Symbol("y"), SymbolStatsEstimate.builder() .setLowValue(0) .setHighValue(3) .setNullsFraction(0) .build()) .addSymbolStatistics(new Symbol("z"), zStats) .build()) .check(check -> check .symbolStats("sum", symbolStatsAssertion -> symbolStatsAssertion
Optional.of(new ComparisonExpression(EQUAL, p.symbol("A1").toSymbolReference(), p.symbol("B1").toSymbolReference())))) .overrideStats("valuesA", PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(ImmutableMap.of(new Symbol("A1"), new SymbolStatsEstimate(0, 100, 0, 100, 10))) .build()) .overrideStats("valuesB", PlanNodeStatsEstimate.builder() .setOutputRowCount(5) .addSymbolStatistics(ImmutableMap.of( new Symbol("B1"), new SymbolStatsEstimate(0, 100, 0, 100, 5), new Symbol("B2"), new SymbolStatsEstimate(0, 100, 0, 100, 5))) .build()) .overrideStats("valuesC", PlanNodeStatsEstimate.builder() .setOutputRowCount(1000) .addSymbolStatistics(ImmutableMap.of(new Symbol("C1"), new SymbolStatsEstimate(0, 100, 0, 100, 100))) .build()) .matches( join(
.setOutputRowCount(10000) .addSymbolStatistics(ImmutableMap.of(new Symbol("A1"), new SymbolStatsEstimate(0, 100, 0, 640000, 100))) .build(); PlanNodeStatsEstimate valuesB = PlanNodeStatsEstimate.builder() .setOutputRowCount(10000) .addSymbolStatistics(ImmutableMap.of(new Symbol("B1"), new SymbolStatsEstimate(0, 100, 0, 640000, 100))) .build();
Optional.of(new ComparisonExpression(EQUAL, p.symbol("A1").toSymbolReference(), p.symbol("B1").toSymbolReference())))) .overrideStats("valuesA", PlanNodeStatsEstimate.builder() .setOutputRowCount(40) .addSymbolStatistics(ImmutableMap.of(new Symbol("A1"), new SymbolStatsEstimate(0, 100, 0, 100, 10))) .build()) .overrideStats("valuesB", PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(ImmutableMap.of( new Symbol("B1"), new SymbolStatsEstimate(0, 100, 0, 100, 10), new Symbol("B2"), new SymbolStatsEstimate(0, 100, 0, 100, 10))) .build()) .overrideStats("valuesC", PlanNodeStatsEstimate.builder() .setOutputRowCount(100) .addSymbolStatistics(ImmutableMap.of(new Symbol("C1"), new SymbolStatsEstimate(99, 199, 0, 100, 100))) .build()) .matches( join(
}) .withSourceStats(0, PlanNodeStatsEstimate.builder() .setOutputRowCount(10) .addSymbolStatistics(new Symbol("a"), stats) .addSymbolStatistics(new Symbol("b"), stats) .build()) .withSourceStats(1, PlanNodeStatsEstimate.builder() .setOutputRowCount(20) .addSymbolStatistics(new Symbol("c"), stats) .build()) .check(check -> check .outputRowsCount(10)
.addSymbolStatistics(new Symbol("x"), SymbolStatsEstimate.builder() .setLowValue(-1) .setHighValue(10) .setAverageRowSize(2.0) .build()) .addSymbolStatistics(new Symbol("y"), SymbolStatsEstimate.builder() .setLowValue(-2) .setHighValue(5) .setAverageRowSize(2.0) .build()) .setOutputRowCount(10) .build();
}) .withSourceStats(LEFT_SOURCE_ID, PlanNodeStatsEstimate.builder() .setOutputRowCount(1000) .addSymbolStatistics(new Symbol("a"), aStats) .addSymbolStatistics(new Symbol("b"), bStats) .build()) .withSourceStats(RIGHT_SOURCE_ID, PlanNodeStatsEstimate.builder() .setOutputRowCount(2000) .addSymbolStatistics(new Symbol("c"), cStats) .build()) .check(check -> { check.outputRowsCount(720)