Skip to content

Commit

Permalink
[fix](nereids) prune partition bug in pattern ColA <> ColB apache#25769
Browse files Browse the repository at this point in the history
in predicate rewrite phase, we eliminate some conjuncts which contains un-interested columns.
for example: T (a, b) partition by (a)
interest cols: a
uninsterest cols: b
for parition prune,
filter "a=1 and a>b" is equivalent to "a=1",
filter "a=1 or a>b" is equivalent to "TRUE"
  • Loading branch information
englefly authored and wsjz committed Nov 19, 2023
1 parent d04b2e1 commit 412bc34
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.nereids.CascadesContext;
import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext;
import org.apache.doris.nereids.rules.expression.rules.TryEliminateUninterestedPredicates.Context;
import org.apache.doris.nereids.trees.expressions.And;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral;
Expand Down Expand Up @@ -104,6 +105,27 @@ public Expression visit(Expression originExpr, Context parentContext) {
return expr;
}

@Override
public Expression visitAnd(And and, Context parentContext) {
Expression left = and.left();
Context leftContext = new Context();
Expression newLeft = this.visit(left, leftContext);
if (leftContext.childrenContainsNonInterestedSlots) {
newLeft = BooleanLiteral.TRUE;
}

Expression right = and.right();
Context rightContext = new Context();
Expression newRight = this.visit(right, rightContext);
if (rightContext.childrenContainsNonInterestedSlots) {
newRight = BooleanLiteral.TRUE;
}
Expression expr = new And(newLeft, newRight).accept(FoldConstantRuleOnFE.INSTANCE, expressionRewriteContext);
parentContext.childrenContainsInterestedSlots =
rightContext.childrenContainsInterestedSlots || leftContext.childrenContainsInterestedSlots;
return expr;
}

@Override
public Expression visitSlot(Slot slot, Context context) {
boolean isInterestedSlot = interestedSlots.contains(slot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ public void prunePartitionWithOrPredicate() {
public void canNotPruneComplexPredicate() {
test("test_range_parts", "(part = 10) or (part + id = 1)", 4);
test("test_range_parts", "(part + id = 1) and (part = 4)", 1);
test("test_range_parts", "(part = 2) and (part <> id)", 1);
test("test_range_parts", "(part = 2) or (part <> id)", 4);
}

@Test
Expand Down

0 comments on commit 412bc34

Please sign in to comment.