vlsi commented on a change in pull request #1703: [CALCITE-2450] Normalize 
RexCall predicates when computing digest
URL: https://github.com/apache/calcite/pull/1703#discussion_r362553258
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java
 ##########
 @@ -120,24 +121,23 @@ public static EnumerableHashJoin create(
       }
     }
 
+    RelOptCostFactory costFactory = planner.getCostFactory();
     // Cheaper if the smaller number of rows is coming from the LHS.
     // Model this by adding L log L to the cost.
     final double rightRowCount = right.estimateRowCount(mq);
     final double leftRowCount = left.estimateRowCount(mq);
-    if (Double.isInfinite(leftRowCount)) {
-      rowCount = leftRowCount;
-    } else {
-      rowCount += Util.nLogN(leftRowCount);
-    }
-    if (Double.isInfinite(rightRowCount)) {
-      rowCount = rightRowCount;
-    } else {
-      rowCount += rightRowCount;
+    if (Double.isInfinite(leftRowCount) || Double.isInfinite(rightRowCount)) {
+      return costFactory.makeInfiniteCost();
     }
     if (isSemiJoin()) {
-      return planner.getCostFactory().makeCost(rowCount, 0, 
0).multiplyBy(.01d);
+      // For semi- and anti- the right input is hashed
+      rowCount += rightRowCount * 1.1d;
+      return costFactory.makeCost(rowCount, 0, 0).multiplyBy(.01d);
     } else {
-      return planner.getCostFactory().makeCost(rowCount, 0, 0);
+      // Lots of plans assumed the left join was hashed, so
+      // we adjust a cost accordingly
+      rowCount += leftRowCount * 1.1d;
+      return costFactory.makeCost(rowCount, 0, 0);
 
 Review comment:
   The problem here is not 1.1, but the problem is join cardinality estimation.
   Calcite tends to over-estimate the join cardinality, thus leftRowCount and 
rightRowCount tend to be noise when compared with the estimated join 
cardinality, thus all those `+= leftRowCount * 1.1d` change nothing.
   
   So a series of patches (https://issues.apache.org/jira/browse/CALCITE-3666, 
https://issues.apache.org/jira/browse/CALCITE-3661) is required before this 
costing could provide any meaningful results :(

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