korlov42 commented on a change in pull request #8456:
URL: https://github.com/apache/ignite/pull/8456#discussion_r530894211



##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/metadata/IgniteMdRowCount.java
##########
@@ -47,6 +48,63 @@
         return joinRowCount(mq, rel);
     }
 
+    /** */
+    public Double getRowCount(IgniteCorrelatedNestedLoopJoin rel, 
RelMetadataQuery mq) {
+        if (!rel.getJoinType().projectsRight()) {
+            // Create a RexNode representing the selectivity of the
+            // semijoin filter and pass it to getSelectivity
+            RexNode semiJoinSelectivity =
+                RelMdUtil.makeSemiJoinSelectivityRexNode(mq, rel);
+
+            return multiply(mq.getSelectivity(rel.getLeft(), 
semiJoinSelectivity),
+                mq.getRowCount(rel.getLeft()));
+        }
+
+        // Row count estimates of 0 will be rounded up to 1.
+        // So, use maxRowCount where the product is very small.
+        final Double left = mq.getRowCount(rel.getLeft());
+        final Double right = mq.getRowCount(rel.getRight());
+
+        if (left == null || right == null)
+            return null;
+
+        if (left <= 1D || right <= 1D) {
+            Double max = mq.getMaxRowCount(rel);
+            if (max != null && max <= 1D)
+                return max;
+        }
+
+        JoinInfo joinInfo = rel.analyzeCondition();
+
+        ImmutableIntList leftKeys = joinInfo.leftKeys;
+        ImmutableIntList rightKeys = joinInfo.rightKeys;
+
+        if (F.isEmpty(leftKeys) || F.isEmpty(rightKeys)) {
+            if (F.isEmpty(leftKeys))
+                return left * right;
+            else
+                return left * right * mq.getSelectivity(rel, 
rel.getCondition());
+        }
+

Review comment:
       because rel.estimateRowCount(mq) uses this method to estimate row count




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