hsyuan commented on a change in pull request #1992:
URL: https://github.com/apache/calcite/pull/1992#discussion_r432435044



##########
File path: core/src/main/java/org/apache/calcite/plan/volcano/RelSubset.java
##########
@@ -293,7 +293,7 @@ public double estimateRowCount(RelMetadataQuery mq) {
     return list;
   }
 
-  RelSet getSet() {
+  public RelSet getSet() {

Review comment:
       Why make it public?

##########
File path: core/src/main/java/org/apache/calcite/plan/volcano/RelSet.java
##########
@@ -73,7 +74,14 @@
    * set.
    */
   RelSet equivalentSet;
-  RelNode rel;
+
+  /**
+   * The first RelNode added to the set or the RelNode with highest confidence
+   * level of estimated statistics.
+   * The logical properties of the RelSet, including row count, uniqueness, 
etc,
+   * are determined by this RelNode.
+   */
+  RelNode originalRel;

Review comment:
       The name is a little bit misleading. Before this patch, it is indeed 
original rel, but after this patch, it isn't original rel anymore. We could 
just call it as it is.

##########
File path: core/src/main/java/org/apache/calcite/plan/volcano/RelSet.java
##########
@@ -490,4 +500,50 @@ void mergeWith(
       planner.fireRules(subset);
     }
   }
+
+  private void checkAndUpdateOriginalRel(RelNode newRel) {
+    if (newRel instanceof LogicalNode && this.originalRel instanceof 
LogicalNode
+        && ((LogicalNode) newRel).getStatsEstimateConfidence().compareTo(
+            ((LogicalNode) this.originalRel).getStatsEstimateConfidence()) > 
0) {
+      this.originalRel = newRel;
+
+      // Invalidate parent sets original rel meta cache since child set 
properties might
+      // have been changed.
+      HashSet<RelSet> newParentSets = getParentSets();
+      HashSet<RelSet> allParentSets = new HashSet<>();
+      while (!newParentSets.isEmpty()) {
+        allParentSets.addAll(newParentSets);
+        HashSet<RelSet> validParents = new HashSet<>();
+        for (RelSet set : newParentSets) {
+          HashSet<RelSet> parents = set.getParentSets();
+          for (RelSet s : parents) {
+            // To handle cycle references between sets
+            if (!allParentSets.contains(s)) {
+              validParents.add(s);
+            }
+          }
+        }
+        newParentSets = validParents;
+      }
+      for (RelSet set : allParentSets) {
+        final RelMetadataQuery mq = 
set.originalRel.getCluster().getMetadataQuery();
+        mq.clearCache(set.originalRel);
+      }
+    }
+  }
+
+  private HashSet<RelSet> getParentSets() {
+    HashSet<RelSet> results = new HashSet<>();
+    VolcanoPlanner planner = (VolcanoPlanner) 
this.originalRel.getCluster().getPlanner();
+    assert planner != null;
+
+    for (RelNode rel : getParentRels()) {
+      RelSet set = planner.getSet(rel);

Review comment:
       If it is already pruned, can we skip?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to