julianhyde commented on code in PR #4022:
URL: https://github.com/apache/calcite/pull/4022#discussion_r1826318264


##########
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java:
##########
@@ -170,6 +170,13 @@ private static RexNode rewriteCollection(RexSubQuery e,
    */
   private static RexNode rewriteSome(RexSubQuery e, Set<CorrelationId> 
variablesSet,
       RelBuilder builder, int subQueryIndex) {
+    // If the sub-query is guaranteed to return 0 row, just return
+    // FALSE.
+    final RelMetadataQuery mq = e.rel.getCluster().getMetadataQuery();
+    final Double maxRowCount = mq.getMaxRowCount(e.rel);
+    if (maxRowCount != null && maxRowCount < 1D) {

Review Comment:
   Sure. If you can find a better place to put the logic at 
https://github.com/apache/calcite/blob/3db4dd1ebf04abaf74d29464ae311a598ae929f7/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java#L456
 then do it. Maybe a method `@Nullable Boolean 
RelMetadataQuery.isEmpty(RelNode)` (where true means always empty, false means 
always non-empty, null for everything else).
   
   I cannot imagine a case where a provider would return a maxRowCount value 
less than one where the relation was not guaranteed empty, so I wouldn't worry 
too much whether the condition is `< 1D` or `== 0D`.



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