Skip to content

Commit

Permalink
fix bug for A>n, where A.max is infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Aug 26, 2024
1 parent 2f84873 commit 5570b57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public double overlapPercentWith(StatisticRange other) {

double lengthOfIntersect = dataType.rangeLength(Math.min(this.high, other.high), Math.max(this.low, other.low));
if (Double.isInfinite(lengthOfIntersect)) {
if (Double.isFinite(this.distinctValues) && Double.isFinite(other.distinctValues)) {
return Math.min(other.distinctValues / this.distinctValues, 1);
}
// if (Double.isFinite(this.distinctValues) && Double.isFinite(other.distinctValues)) {
// return Math.min(other.distinctValues / this.distinctValues, 1);
// }
return INFINITE_TO_INFINITE_RANGE_INTERSECT_OVERLAP_HEURISTIC_FACTOR;
}
if (lengthOfIntersect == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,4 +1365,33 @@ public void testStringRangeColToCol() {
Statistics agrtc = new FilterEstimation().estimate(new GreaterThan(a, c), baseStats);
Assertions.assertEquals(50, agrtc.getRowCount());
}

@Test
void testAndWithInfinite() {
SlotReference a = new SlotReference("a", new VarcharType(25));
ColumnStatisticBuilder columnStatisticBuilderA = new ColumnStatisticBuilder()
.setNdv(233)
.setAvgSizeByte(4)
.setNumNulls(0)
.setCount(133493073);

SlotReference b = new SlotReference("b", new VarcharType(25));
ColumnStatisticBuilder columnStatisticBuilderB = new ColumnStatisticBuilder()
.setNdv(488)
.setAvgSizeByte(25)
.setNumNulls(0)
.setCount(133493073);
StatisticsBuilder statsBuilder = new StatisticsBuilder();
statsBuilder.setRowCount(133493073);
statsBuilder.putColumnStatistics(a, columnStatisticBuilderA.build());
statsBuilder.putColumnStatistics(b, columnStatisticBuilderB.build());

Expression predicate = new And(
new GreaterThanEqual(a, new org.apache.doris.nereids.trees.expressions.literal.StringLiteral("2024-05-14")),
new GreaterThan(b, new IntegerLiteral(0))
);

Statistics stats = new FilterEstimation().estimate(predicate, statsBuilder.build());
System.out.println(stats);
}
}

0 comments on commit 5570b57

Please sign in to comment.