github-actions[bot] commented on code in PR #70516:
URL: https://github.com/apache/doris/pull/70516#discussion_r4623625961


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPushDownVisitor.java:
##########
@@ -308,6 +316,25 @@ && canPushThroughJoinChild(join, false, ctx)) {
                 }
                 if (newTarget != null && newTarget.getInputSlots().size() == 1
                         && !newTarget.equals(ctx.srcExpr)) {
+                    if (expandByOuterJoin) {
+                        Plan preserved = join.getJoinType().isLeftOuterJoin() 
? leftNode : rightNode;
+                        Plan nonPreserved = 
join.getJoinType().isLeftOuterJoin() ? rightNode : leftNode;
+                        // For (L LEFT JOIN R ON L.k = R.k) JOIN E ON L.k = 
E.k, an R row
+                        // matching a needed L row must pass the same RF(E.k). 
Only derive
+                        // from the preserved side: outer join output keys are 
not equivalent.
+                        // Limit this to direct keys with identical types so 
both targets use
+                        // the same equality and RF encoding without 
additional conversions.
+                        // A computed key such as R.k + 1 may already be a 
projected slot;
+                        // unlike a direct column alias, it has no original 
column metadata.
+                        if (!(equalTo instanceof EqualTo)
+                                || !PlanUtils.isColumnRef(ctx.probeExpr) || 
!PlanUtils.isColumnRef(newTarget)

Review Comment:
   [P1] Stop expanded filters at row-count-sensitive operators
   
   Direct-column metadata also survives row-count-sensitive operators, so these 
guards admit a target that the generic visitor must not push to its scan. For 
example:
   
   ```sql
   SELECT l.k, d.v FROM L l
   LEFT JOIN D d ON l.k = (SELECT r.k FROM R r)
   JOIN E e ON l.k = e.k
   ```
   
   With INT keys, L=E={2}, one D row, R={1,2}, join reorder/pruning disabled, 
runtime_filter_type=1 and RF wait enabled, the default scalar rewrites produce 
this reduced tree:
   
   ```text
   HashJoin(L.k = E.k) [build E={2}]
     LeftOuterHashJoin(L.k = R.k)
       Scan L={2}
       CrossJoin
         Scan D
         AssertNumRows(EQ 1)
           Scan R={1,2}
     Scan E={2}
   ```
   
   `JOIN_SUBQUERY_TO_APPLY` substitutes the original nullable R.k slot directly 
into the ON equality and attaches the uncorrelated Apply to D; 
`ScalarApplyToJoin` supplies the assertion. Thus the new column/type/direction 
guards pass. `visitPhysicalNestedLoopJoin` traverses the CROSS, and 
`PlanVisitor.visitPhysicalAssertNumRows` falls through to generic `visit`, 
registering RF({2}) below the assertion. The scalar query must fail for two 
rows; expansion makes it see one row and succeed. Previously this ancestor 
filter reached only L.
   
   The same missing barrier changes outer-join results for `R ORDER BY k LIMIT 
1` when `LIMIT_SORT_TO_TOP_N,ELIMINATE_SORT` are disabled: retained Limit(Sort) 
selects 1 before expansion and 2 after RF({2}), changing the right output from 
NULL to 2. Ordinary merged TopN is already protected. Stop traversal at 
`PhysicalAssertNumRows` and `PhysicalLimit`, and cover these non-preserved 
subtrees.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to