rubenada commented on code in PR #4574:
URL: https://github.com/apache/calcite/pull/4574#discussion_r2421565203


##########
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java:
##########
@@ -895,12 +895,8 @@ private static void matchFilter(SubQueryRemoveRule rule,
           LogicVisitor.find(RelOptUtil.Logic.TRUE, ImmutableList.of(c), e);
       final Set<CorrelationId>  variablesSet =
           RelOptUtil.getVariablesUsed(e.rel);
-      // Filter without variables could be handled before this change, we do 
not want
-      // to break it yet for compatibility reason.
-      if (!filterVariablesSet.isEmpty()) {
-        // Only consider the correlated variables which originated from this 
sub-query level.
-        variablesSet.retainAll(filterVariablesSet);
-      }
+      // Only consider the correlated variables which originated from this 
sub-query level.

Review Comment:
   We can't do that because there's the possibility of a filter with 
filter.getVariablesSet() = {$cor0, $cor1} whose condition is a combination of 
two RexSubQueries: filter.getCondition = RexSubQuery0 (using $cor0) AND 
RexSubQuery1 (using $cor1)  ; thus when processing each RexSubQuery we need to 
consider only the relevant variables ($cor0 for RexSubQuery0; and $cor1 for 
RexSubQuery1).
   Also, we can't simply use RexSubQuery's variables (via 
RelOptUtil#getVariablesUsed) because it may happen that our RexSubQuery0 uses 
$cor0 and $cor2, but this $cor2 belongs to the scope of a different filter (we 
have nested correlated sub-queries); therefore we need the intersection between 
the Filter's variableSet and the RexSubQuery's  variableSet.



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