Repository: calcite
Updated Branches:
  refs/heads/master b916a65b9 -> eaa84951c


[CALCITE-1100] If constant reduction no-ops, don't create a new RelNode 
(Hsuan-Yi Chu)

If RelOptPlanner.Executor cannot reduce to a new expression, do not
generate a new plan. (The new plan would be equivalent to the original
one, the Importance of the original plan would be forced as ZERO and
prevent other rules from being fired.)


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/eaa84951
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/eaa84951
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/eaa84951

Branch: refs/heads/master
Commit: eaa84951c53b0602c352b654236d38c8bb8efe26
Parents: b916a65
Author: Hsuan-Yi Chu <[email protected]>
Authored: Wed Feb 24 18:09:25 2016 -0800
Committer: Julian Hyde <[email protected]>
Committed: Thu Feb 25 15:10:14 2016 -0800

----------------------------------------------------------------------
 .../org/apache/calcite/rel/rules/ReduceExpressionsRule.java  | 6 ++++++
 core/src/main/java/org/apache/calcite/rex/RexUtil.java       | 8 ++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/eaa84951/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
index 1fe0218..6c0238a 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
@@ -507,6 +507,12 @@ public abstract class ReduceExpressionsRule extends 
RelOptRule {
     final List<RexNode> reducedValues = Lists.newArrayList();
     executor.reduce(rexBuilder, constExps2, reducedValues);
 
+    // Use RexNode.digest to judge whether each newly generated RexNode
+    // is equivalent to the original one.
+    if (RexUtil.strings(constExps).equals(RexUtil.strings(reducedValues))) {
+      return false;
+    }
+
     // For Project, we have to be sure to preserve the result
     // types, so always cast regardless of the expression type.
     // For other RelNodes like Filter, in general, this isn't necessary,

http://git-wip-us.apache.org/repos/asf/calcite/blob/eaa84951/core/src/main/java/org/apache/calcite/rex/RexUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexUtil.java 
b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
index f26c783..12ca400 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexUtil.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
@@ -1903,8 +1903,7 @@ public class RexUtil {
             map.put(conjunction.toString(), conjunction);
           }
         } else {
-          map.keySet().retainAll(
-              Lists.transform(RelOptUtil.conjunctions(node), TO_STRING));
+          map.keySet().retainAll(strings(RelOptUtil.conjunctions(node)));
         }
       }
       return map;
@@ -1930,6 +1929,11 @@ public class RexUtil {
     }
   }
 
+  /** Transforms a list of expressions to the list of digests. */
+  public static List<String> strings(List<RexNode> list) {
+    return Lists.transform(list, TO_STRING);
+  }
+
   /** Helps {@link org.apache.calcite.rex.RexUtil#toDnf}. */
   private static class DnfHelper {
     final RexBuilder rexBuilder;

Reply via email to