From dd171834ee34ba1478d69160e6887591923ef970 Mon Sep 17 00:00:00 2001 From: wangyanjing Date: Fri, 6 Dec 2024 12:11:16 +0800 Subject: [PATCH] [CALCITE-6718] Optimize SubstitutionVisitor's splitFilter with early return and uniform simplification for equivalence checking --- .../org/apache/calcite/plan/SubstitutionVisitor.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java index 5a76cb99b3e..deef3487f2f 100644 --- a/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java +++ b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java @@ -297,8 +297,11 @@ void register(MutableRel result, MutableRel query) { RexNode condition, RexNode target) { final RexBuilder rexBuilder = simplify.rexBuilder; condition = simplify.simplify(condition); - target = simplify.simplify(target); RexNode condition2 = canonizeNode(rexBuilder, condition); + if (target.isAlwaysTrue()) { + return condition2; + } + target = simplify.simplify(target); RexNode target2 = canonizeNode(rexBuilder, target); // First, try splitting into ORs. @@ -322,7 +325,9 @@ void register(MutableRel result, MutableRel query) { ImmutableList.of(condition2, target2)); RexNode r = canonizeNode(rexBuilder, simplify.simplifyUnknownAsFalse(x2)); - if (!r.isAlwaysFalse() && isEquivalent(condition2, r)) { + RexNode simplifiedCond2 = + canonizeNode(rexBuilder, simplify.simplifyUnknownAsFalse(condition2)); + if (!r.isAlwaysFalse() && isEquivalent(simplifiedCond2, r)) { List conjs = RelOptUtil.conjunctions(r); for (RexNode e : RelOptUtil.conjunctions(target2)) { removeAll(conjs, e);