amaliujia commented on a change in pull request #2131:
URL: https://github.com/apache/calcite/pull/2131#discussion_r482294819



##########
File path: core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java
##########
@@ -731,19 +734,22 @@ public static Double getJoinRowCount(RelMetadataQuery mq, 
Join join,
         return max;
       }
     }
-    double product = left * right;
-
-    return product * mq.getSelectivity(join, condition);
-  }
 
-  /** Returns an estimate of the number of rows returned by a semi-join. */
-  public static Double getSemiJoinRowCount(RelMetadataQuery mq, RelNode left,
-      RelNode right, JoinRelType joinType, RexNode condition) {
-    final Double leftCount = mq.getRowCount(left);
-    if (leftCount == null) {
-      return null;
+    double product = left * right;
+    double selectivity = mq.getSelectivity(join, condition);
+    double innerRowCount = product * selectivity;
+    switch (join.getJoinType()) {
+    case INNER:
+      return innerRowCount;
+    case LEFT:
+      return left * (1D - selectivity) + innerRowCount;
+    case RIGHT:
+      return right * (1D - selectivity) + innerRowCount;

Review comment:
       (1D - selectivity) * left/right to estimate the number of `row,null` 
tuple makes sense (although it relies on a good estimation on `selectivity`, 
which usually is a hard engineering problem :-))




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