xndai commented on a change in pull request #1440: [CALCITE-2166] Cumulative 
cost of RelSubset.best RelNode is increased…
URL: https://github.com/apache/calcite/pull/1440#discussion_r322065445
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/volcano/RelSubset.java
 ##########
 @@ -344,15 +344,29 @@ void propagateCostImprovements0(VolcanoPlanner planner, 
RelMetadataQuery mq,
       return;
     }
     try {
-      final RelOptCost cost = planner.getCost(rel, mq);
-      if (cost.isLt(bestCost)) {
-        LOGGER.trace("Subset cost improved: subset [{}] cost was {} now {}", 
this, bestCost, cost);
+      RelOptCost cost = planner.getCost(rel, mq);
+      boolean updateBest = cost.isLt(bestCost);
+
+      // Best rel's cost is increased, we need to search for new best rel
+      if (rel == best && bestCost.isLt(cost)) {
+        updateBest = true;
 
 Review comment:
   The loop is to guarantee the new best would be the one with cheapest cost in 
current sub set. It could be a different node if the cost of the original best 
has increased. As I mentioned in the JIRA, this approach doesn't guarantee an 
optimal result but does make sure the memo is consistent. To get optimal 
result, we either need to make sure RelSubset row count doesn't change (it 
shouldn't change in theory), or we have multiple best node candidates in a 
subset. But the change would be too drastic and the runtime overhead is non 
trivial. 

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to