NobiGo commented on code in PR #2781:
URL: https://github.com/apache/calcite/pull/2781#discussion_r859505596


##########
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java:
##########
@@ -450,8 +450,18 @@ private static RexNode rewriteSome(RexSubQuery e, 
Set<CorrelationId> variablesSe
    */
   private static RexNode rewriteExists(RexSubQuery e, Set<CorrelationId> 
variablesSet,
       RelOptUtil.Logic logic, RelBuilder builder) {
+    // If the sub-query is guaranteed to produce at least one row, just return
+    // TRUE.
+    final RelMetadataQuery mq = e.rel.getCluster().getMetadataQuery();
+    final Double minRowCount = mq.getMinRowCount(e.rel);
+    if (minRowCount != null && minRowCount >= 1D) {
+      return builder.literal(true);
+    }
+    final Double maxRowCount = mq.getMaxRowCount(e.rel);
+    if (maxRowCount != null && maxRowCount < 1D) {
+      return builder.literal(false);

Review Comment:
   Done.



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

To unsubscribe, e-mail: [email protected]

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

Reply via email to