calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject calcite git commit: [CALCITE-1100] If constant reduction no-ops, don't create a new RelNode (Hsuan-Yi Chu) [Forced Update!]
Date Thu, 25 Feb 2016 23:55:45 GMT
Repository: calcite
Updated Branches:
  refs/heads/master eaa84951c -> 25d1e42a7 (forced update)


[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.)

Close apache/calcite#199


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

Branch: refs/heads/master
Commit: 25d1e42a7fb248d24caaaa949779e06056c9916c
Parents: b916a65
Author: Hsuan-Yi Chu <hsuanyi@usc.edu>
Authored: Wed Feb 24 18:09:25 2016 -0800
Committer: Julian Hyde <jhyde@apache.org>
Committed: Thu Feb 25 15:55:25 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/25d1e42a/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/25d1e42a/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;


Mime
View raw message