yashlimbad commented on code in PR #4840:
URL: https://github.com/apache/calcite/pull/4840#discussion_r3084149741


##########
core/src/main/java/org/apache/calcite/plan/RelOptUtil.java:
##########
@@ -2934,15 +2934,40 @@ public static boolean classifyFilters(
     ImmutableBitSet rightBitmap =
         ImmutableBitSet.range(nSysFields + nFieldsLeft, nTotalFields);
 
+    // Correlation variables introduced by this join itself: i.e. ids whose
+    // binding is established by *this* join (the left input is the producer,
+    // the right input is the consumer). A predicate that references any of
+    // these cannot be pushed to the LEFT input -- the left subtree has no
+    // binder for the variable above it, so the reference would be stranded.
+    // Pushing such a predicate to the RIGHT input is still safe (the right
+    // subtree is the natural consumer of the binding established by this
+    // join), and it can of course stay on the join itself.
+    final Set<CorrelationId> joinCorrelationIds = joinRel instanceof Join
+        ? joinRel.getVariablesSet()
+        : ImmutableSet.of();
+
     final List<RexNode> filtersToRemove = new ArrayList<>();
     for (RexNode filter : filters) {
-      final InputFinder inputFinder = InputFinder.analyze(filter);
+
+      // Only consider correlation ids bound by *this* join when computing
+      // the input bitmap of a sub-query inside the predicate. Foreign
+      // correlation ids are bound by an outer scope and their
+      // correlationColumns indices would otherwise alias onto unrelated
+      // columns of this join's row type, mis-classifying the predicate.
+      final InputFinder inputFinder = InputFinder.analyze(filter, 
joinCorrelationIds);
       final ImmutableBitSet inputBits = inputFinder.build();
 
+      // Disable left-push only for filters that reference a CorrelationId
+      // bound by this join.

Review Comment:
   yes I did the same, forgot to update comments. appologies



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