Skip to content

Commit

Permalink
[fix](nereids) stats derive for "not equal“, avoid to derive zero ndv (
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly authored Feb 29, 2024
1 parent e7573ac commit bd4bb58
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.doris.nereids.trees.expressions.ComparisonPredicate;
import org.apache.doris.nereids.trees.expressions.CompoundPredicate;
import org.apache.doris.nereids.trees.expressions.EqualPredicate;
import org.apache.doris.nereids.trees.expressions.EqualTo;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.GreaterThan;
import org.apache.doris.nereids.trees.expressions.GreaterThanEqual;
Expand Down Expand Up @@ -376,9 +375,9 @@ public Statistics visitNot(Not not, EstimationContext context) {
"Not-predicate meet unexpected child: %s", child.toSql());
if (child instanceof Like) {
rowCount = context.statistics.getRowCount() - childStats.getRowCount();
colBuilder.setNdv(originColStats.ndv - childColStats.ndv);
colBuilder.setNdv(Math.max(1.0, originColStats.ndv - childColStats.ndv));
} else if (child instanceof InPredicate) {
colBuilder.setNdv(originColStats.ndv - childColStats.ndv);
colBuilder.setNdv(Math.max(1.0, originColStats.ndv - childColStats.ndv));
colBuilder.setMinValue(originColStats.minValue)
.setMinExpr(originColStats.minExpr)
.setMaxValue(originColStats.maxValue)
Expand All @@ -389,8 +388,8 @@ public Statistics visitNot(Not not, EstimationContext context) {
.setMinExpr(originColStats.minExpr)
.setMaxValue(originColStats.maxValue)
.setMaxExpr(originColStats.maxExpr);
} else if (child instanceof EqualTo) {
colBuilder.setNdv(originColStats.ndv - childColStats.ndv);
} else if (child instanceof EqualPredicate) {
colBuilder.setNdv(Math.max(1.0, originColStats.ndv - childColStats.ndv));
colBuilder.setMinValue(originColStats.minValue)
.setMinExpr(originColStats.minExpr)
.setMaxValue(originColStats.maxValue)
Expand Down

0 comments on commit bd4bb58

Please sign in to comment.