You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by hy...@apache.org on 2020/02/13 00:25:41 UTC

[calcite] branch master updated: [CALCITE-3785] HepPlanner.belongToDag() doesn't have to use mapDigestToVertex (Xiening Dai)

This is an automated email from the ASF dual-hosted git repository.

hyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new a09923f  [CALCITE-3785] HepPlanner.belongToDag() doesn't have to use mapDigestToVertex (Xiening Dai)
a09923f is described below

commit a09923ff8dcb707c5573b37e182308f90dfb52fe
Author: Xiening Dai <xn...@live.com>
AuthorDate: Tue Feb 11 15:12:20 2020 -0800

    [CALCITE-3785] HepPlanner.belongToDag() doesn't have to use mapDigestToVertex (Xiening Dai)
    
    To test whether or not a vertex belongs to DAG, we can simply do
    graph.vertexSet().contains(vertex). There's no need to look up in
    mapDigestToVertex map, which incurs overhead of creating the map key. This
    problem was amplified by CALCITE-3713.
    
    Close #1799
---
 .../main/java/org/apache/calcite/plan/hep/HepPlanner.java | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java b/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java
index 71f1c5b..a018b01 100644
--- a/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java
+++ b/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java
@@ -498,17 +498,11 @@ public class HepPlanner extends AbstractRelOptPlanner {
     }
   }
 
-  /** Returns whether the vertex is valid. */
-  private boolean belongsToDag(HepRelVertex vertex) {
-    Pair<String, List<RelDataType>> key = key(vertex.getCurrentRel());
-    return mapDigestToVertex.get(key) != null;
-  }
-
   private HepRelVertex applyRule(
       RelOptRule rule,
       HepRelVertex vertex,
       boolean forceConversions) {
-    if (!belongsToDag(vertex)) {
+    if (!graph.vertexSet().contains(vertex)) {
       return null;
     }
     RelTrait parentTrait = null;
@@ -629,6 +623,13 @@ public class HepPlanner extends AbstractRelOptPlanner {
     if (!operand.matches(rel)) {
       return false;
     }
+    for (RelNode input : rel.getInputs()) {
+      if (!(input instanceof HepRelVertex)) {
+        // The graph could be partially optimized for materialized view. In that
+        // case, the input would be a RelNode and shouldn't be matched again here.
+        return false;
+      }
+    }
     bindings.add(rel);
     @SuppressWarnings("unchecked")
     List<HepRelVertex> childRels = (List) rel.getInputs();