zabetak commented on code in PR #4022:
URL: https://github.com/apache/calcite/pull/4022#discussion_r1824926676
##########
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:
We have [rule in PruneEmptyRules
](https://github.com/apache/calcite/blob/ed6c33eb1d27882b26fc16b995dde78de1709aff/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java#L649)
that does:
```java
return maxRowCount != null && maxRowCount == 0.0;
```
Given that comparisons with doubles are inherently imprecise we may need to
revisit that rule as well. Should we employ a threshold comparison?
--
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]