You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "NobiGo (via GitHub)" <gi...@apache.org> on 2024/11/01 10:32:03 UTC
Re: [PR] [CALCITE-6650] Optimize the IN sub-query and SOME sub-query by Metada… [calcite]
NobiGo commented on code in PR #4022:
URL: https://github.com/apache/calcite/pull/4022#discussion_r1825678979
##########
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:
> I have the same concern as @dssysolyatin. Could we instead check whether it is an instance of `Values` and then call `Values.isEmpty`? (Which is how `PruneEmptyRules` works.)
I think we can't. Now we apply `SubQueryRemoveRule` before `PruneEmptyRules`. so the sub-query is not a VALUES.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org