This is an automated email from the ASF dual-hosted git repository.

englefly pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 02913a22353 [improvement](runtime filter) Expand runtime filters 
through outer joins (#70516)
02913a22353 is described below

commit 02913a223533947c16d602d46ee25c0620e4c59d
Author: minghong <[email protected]>
AuthorDate: Tue Nov 24 17:57:37 2026 +0800

    [improvement](runtime filter) Expand runtime filters through outer joins 
(#70516)
    
    ### Background
    
    Runtime filters from an ancestor hash join can already reach scans
    through lower joins. Equality expansion currently adds targets across
    INNER/SEMI joins, but does not derive targets on the non-preserved side
    of an OUTER join.
    
    ### What problem does this PR solve?
    
    Issue Number: None
    Related PR: None
    PR Type: Enhancement
    
    Problem Summary: In `(L LEFT JOIN R ON L.k = R.k) JOIN E ON L.k = E.k`,
    the runtime filter built from `E.k` can filter `L.k`, while `R` still
    scans and builds rows that cannot match any needed `L` row. This change
    derives an additional target on `R.k`, and handles RIGHT OUTER joins
    symmetrically. The existing RF producer, target registration and
    translation paths are reused; most of the diff adds coverage for plan
    generation and execution semantics.
    
    ### Details
    
    - **Change map:** 31 lines of production changes, 275 lines of
    test-source changes, and 206 lines of automatically generated expected
    results.
    - **Before and after:** An ancestor RF can now reach both the preserved
    join key and the corresponding non-preserved key. Expansion is
    directional and limited to ordinary equality between direct column
    references with identical source/probe/target types. Direct aliases
    retain column metadata; projected computed expressions are excluded.
    FULL OUTER, mark joins and decoupled RF expansion are excluded, and
    existing NULL-safe producer restrictions remain in effect.
    - **Configs and defaults:** Reuses the existing
    `expand_runtime_filter_by_inner_join` session setting, which defaults to
    true. No configuration or protocol fields are added.
    - **Behavior change:** Eligible queries receive additional RF consumers.
    Join results, including unmatched preserved rows, remain unchanged.
    - **Impact on existing users:** Additional filtering can reduce rows
    entering shuffle and hash build. Storage-read and elapsed-time
    improvements depend on selectivity, storage layout and RF arrival time;
    no workload-level performance improvement is claimed here.
    
    ### Testing
    
    - `bash run-fe-ut.sh --run
    org.apache.doris.nereids.postprocess.RuntimeFilterTest`: 57 tests
    passed.
    - `MVN_OPT='-Dmaven.build.cache.enabled=false' FE_MAVEN_THREADS=4 bash
    build.sh --fe --exclude-obs-dependencies -j4`: FE build passed,
    including Checkstyle with zero violations. Verified that the deployed FE
    jar contains the new expansion guard.
    - `bash run-regression-test.sh --conf
    regression-test/conf/regression-conf-gj29031.groovy --run -d
    query_p0/runtime_filter -s outer_join_runtime_filter -genOut`: generated
    expected output on a local single-BE cluster. All eight
    expansion-disabled/enabled result pairs are identical; the plans show
    the added address/phone scan targets.
    - `bash run-regression-test.sh --conf
    regression-test/conf/regression-conf-gj29031.groovy --run -d
    query_p0/runtime_filter,correctness_p0 -s
    outer_join_runtime_filter,test_runtime_filter_outer_join_nullable_side`:
    both suites passed against the saved output. Coverage includes IN,
    BLOOM, MIN_MAX and IN_OR_BLOOM, plus empty non-preserved inputs and
    empty producers.
    - No workload-level performance benchmark was run.
    
    ### Notes for Reviewers
    
    Self-review checkpoints:
    
    - Goal and scope: production changes are confined to
    `RuntimeFilterPushDownVisitor#visitPhysicalHashJoin` and imports;
    `RuntimeFilterGenerator` and `RuntimeFilterTranslator` need no changes.
    - Concurrency: standalone ancestor-build and descendant-build pipelines
    remain independent. Execution coverage waits for the added RF consumers;
    non-blocking context propagation is also tested.
    - Lifecycle: reuses `withNewProbeExpression`, preserving the builder,
    source, filter type, expression order, NDV and non-blocking requirement;
    no new ownership or static initialization is introduced.
    - Parallel paths: covers LEFT/RIGHT OUTER joins, reversed ON operands,
    nested joins, aliases and shared CTE consumers. Existing shared-producer
    eligibility checks remain in place. Nested-loop join expansion is
    outside this hash-equality change.
    - Conditional checks: comments explain the directional proof,
    identical-type restriction and rejection of expressions normalized into
    projected slots.
    - Coverage and results: FE tests check target registration and
    serialized consumers; ordered regression results compare expansion
    disabled/enabled and cover NULLs, duplicates, composite-key cross
    combinations, empty producers and empty non-preserved inputs. Expected
    output is generated by the regression runner.
    - Observability and cost: uses existing Explain RF targets and execution
    RF counters; target registration and legacy grouping remain unchanged.
    Expansion follows child edges and uses existing per-scan deduplication.
    - Compatibility, persistence and writes: no Thrift/protobuf IDs, FE/BE
    variables, storage formats, metadata journals, transactions or
    data-write paths change.
    
    ### Release note
    
    Runtime filter expansion can now derive filters from the preserved side
    to matching keys on the non-preserved side of LEFT/RIGHT OUTER joins,
    reducing unnecessary downstream processing for eligible queries.
    
    ### Check List (For Author)
    
    - Test: See Testing.
    - Behavior changed: Yes (see Details).
    - Does this need documentation: No; optimizer enhancement using an
    existing setting.
    - Pre-submission status: Ready.
    
    ### AI Disclosure
    
    - Tool: OpenAI Codex.
    - Generated: Implementation, tests and PR description.
    - Human review: The user reviewed the optimization approach; the
    generated diff awaits human review.
---
 .../post/AbstractRuntimeFilterPushDownVisitor.java |  85 +++++++++
 .../processor/post/RuntimeFilterGenerator.java     |  11 +-
 .../post/RuntimeFilterPushDownVisitor.java         |  81 ++++----
 .../doris/nereids/processor/post/TopNScanOpt.java  |  13 +-
 .../processor/post/TopnFilterPushDownVisitor.java  |  49 ++---
 .../nereids/postprocess/RuntimeFilterTest.java     | 199 +++++++++++++++++++-
 .../nereids/postprocess/TopNRuntimeFilterTest.java |  26 ++-
 .../runtime_filter/outer_join_runtime_filter.out   | 206 +++++++++++++++++++++
 .../outer_join_runtime_filter_row_count.out        | 119 ++++++++++++
 .../tpcds_sf100/noStatsRfPrune/query40.out         |   4 +-
 .../tpcds_sf100/noStatsRfPrune/query75.out         |  24 +--
 .../tpcds_sf100/noStatsRfPrune/query80.out         |  24 +--
 .../tpcds_sf100/no_stats_shape/query40.out         |   4 +-
 .../tpcds_sf100/no_stats_shape/query75.out         |  24 +--
 .../tpcds_sf100/no_stats_shape/query80.out         |  28 +--
 .../shape_check/tpcds_sf10t_orc/shape/query40.out  |   4 +-
 .../shape_check/tpcds_sf10t_orc/shape/query72.out  |  16 +-
 .../shape_check/tpcds_sf10t_orc/shape/query75.out  |  28 +--
 .../shape_check/tpcds_sf10t_orc/shape/query80.out  |  28 +--
 .../outer_join_runtime_filter.groovy               | 105 +++++++++++
 .../outer_join_runtime_filter_row_count.groovy     | 110 +++++++++++
 21 files changed, 1001 insertions(+), 187 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/AbstractRuntimeFilterPushDownVisitor.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/AbstractRuntimeFilterPushDownVisitor.java
new file mode 100644
index 00000000000..25246ce845f
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/AbstractRuntimeFilterPushDownVisitor.java
@@ -0,0 +1,85 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.processor.post;
+
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalAssertNumRows;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalHashAggregate;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalLimit;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalPartitionTopN;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalRelation;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalRepeat;
+import 
org.apache.doris.nereids.trees.plans.physical.PhysicalStorageLayerAggregate;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalTopN;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+
+import java.util.Set;
+
+/** Applies the shared runtime filter pushdown rules before dispatching to 
each physical operator. */
+abstract class AbstractRuntimeFilterPushDownVisitor<C> extends 
PlanVisitor<Boolean, C> {
+
+    /** Starts or continues pushdown. Every recursive step must use this entry 
point. */
+    public final boolean pushDown(Plan plan, C context) {
+        return !blocksRuntimeFilterPushDown(plan, getProbeExpression(context)) 
&& plan.accept(this, context);
+    }
+
+    protected abstract Expression getProbeExpression(C context);
+
+    private static boolean blocksRuntimeFilterPushDown(Plan plan, Expression 
probe) {
+        // Filtering the input could hide a cardinality error or change which 
rows are selected.
+        if (plan instanceof PhysicalAssertNumRows || plan instanceof 
PhysicalLimit || plan instanceof PhysicalTopN) {
+            return true;
+        }
+        Set<Slot> probeSlots = probe.getInputSlots();
+        if (plan instanceof PhysicalPartitionTopN) {
+            PhysicalPartitionTopN<?> topN = (PhysicalPartitionTopN<?>) plan;
+            // Removing a whole partition preserves the choices of the other 
partitions.
+            if (topN.hasGlobalLimit() || 
!topN.getPartitionKeys().containsAll(probeSlots)) {
+                return true;
+            }
+        }
+        if (plan instanceof PhysicalHashAggregate) {
+            PhysicalHashAggregate<?> aggregate = (PhysicalHashAggregate<?>) 
plan;
+            if (aggregate.getGroupByExpressions().isEmpty()
+                    || 
!aggregate.getGroupByExpressions().containsAll(probeSlots)) {
+                return true;
+            }
+        }
+        if (plan instanceof PhysicalRepeat
+                && !((PhysicalRepeat<?>) 
plan).getCommonGroupingSetExpressions().containsAll(probeSlots)) {
+            // Repeat erases keys absent from a grouping set to NULL.
+            return true;
+        }
+
+        return hasSensitiveExpressions(plan)
+                || (plan instanceof PhysicalRelation && 
probe.containsVolatileOrNoneMovableExpression());
+    }
+
+    static boolean hasSensitiveExpressions(Plan plan) {
+        // A scan filter can remove rows before any expression on this 
operator is evaluated.
+        // For example, assert_true on an unrelated Project output must still 
see those rows.
+        return 
plan.getExpressions().stream().anyMatch(Expression::containsVolatileOrNoneMovableExpression);
+    }
+
+    @Override
+    public final Boolean 
visitPhysicalStorageLayerAggregate(PhysicalStorageLayerAggregate aggregate, C 
context) {
+        return pushDown(aggregate.getRelation(), context);
+    }
+}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterGenerator.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterGenerator.java
index 2364d342f6a..8f1b642067d 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterGenerator.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterGenerator.java
@@ -322,7 +322,7 @@ public class RuntimeFilterGenerator extends 
PlanPostProcessor {
                     // Currently, we only apply RF on PhysicalScan. So skip 
this rf.
                     // example: (select sum(x) as s from A) T join B on T.s=B.s
                     if (pushDownContext.isValid()) {
-                        join.accept(new RuntimeFilterPushDownVisitor(), 
pushDownContext);
+                        new RuntimeFilterPushDownVisitor().pushDown(join, 
pushDownContext);
                     }
                 }
             }
@@ -437,8 +437,7 @@ public class RuntimeFilterGenerator extends 
PlanPostProcessor {
                                 decoupledNdv, -1 /*sentinel: decoupled RF*/);
                 boolean decoupledRfPushed = false;
                 if (pushDownContext.isValid()) {
-                    decoupledRfPushed = join.right().accept(
-                            new RuntimeFilterPushDownVisitor(), 
pushDownContext);
+                    decoupledRfPushed = new 
RuntimeFilterPushDownVisitor().pushDown(join.right(), pushDownContext);
                 }
                 if (decoupledRfPushed) {
                     if (preferDecoupled) {
@@ -767,7 +766,7 @@ public class RuntimeFilterGenerator extends 
PlanPostProcessor {
                                 TRuntimeFilterType.MIN_MAX, 
getMinMaxType(compare),
                                 false, -1, exprOrder);
                 if (pushDownContext.isValid()) {
-                    join.accept(new RuntimeFilterPushDownVisitor(), 
pushDownContext);
+                    new RuntimeFilterPushDownVisitor().pushDown(join, 
pushDownContext);
                 }
             }
         }
@@ -860,7 +859,7 @@ public class RuntimeFilterGenerator extends 
PlanPostProcessor {
                                     ctx, setOp, sourceExpression, 
targetExpression,
                                     type, hasUnknownColStats, 
buildNdvOrRowCount, slotIdx);
                     if (pushDownContext.isValid()) {
-                        setOp.child(childId).accept(pushDownVisitor, 
pushDownContext);
+                        pushDownVisitor.pushDown(setOp.child(childId), 
pushDownContext);
                     }
                 }
             }
@@ -1114,7 +1113,7 @@ public class RuntimeFilterGenerator extends 
PlanPostProcessor {
                         !rf.isBloomFilterSizeCalculatedByNdv(), 
rf.getBuildSideNdv(), rf.getExprOrder())
                         .withNonBlocking(nonBlocking);
         if (pushDownContext.isValid()) {
-            return inputPlanNode.accept(new RuntimeFilterPushDownVisitor(), 
pushDownContext);
+            return new RuntimeFilterPushDownVisitor().pushDown(inputPlanNode, 
pushDownContext);
         }
         return false;
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPushDownVisitor.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPushDownVisitor.java
index b01be65f70a..b29ae57cd34 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPushDownVisitor.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPushDownVisitor.java
@@ -20,6 +20,7 @@ package org.apache.doris.nereids.processor.post;
 import 
org.apache.doris.nereids.processor.post.RuntimeFilterPushDownVisitor.PushDownContext;
 import org.apache.doris.nereids.trees.expressions.Cast;
 import org.apache.doris.nereids.trees.expressions.EqualPredicate;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import org.apache.doris.nereids.trees.expressions.NullSafeEqual;
 import org.apache.doris.nereids.trees.expressions.Slot;
@@ -34,14 +35,12 @@ import 
org.apache.doris.nereids.trees.plans.physical.PhysicalLazyMaterializeOlap
 import org.apache.doris.nereids.trees.plans.physical.PhysicalNestedLoopJoin;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalProject;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalRelation;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalRepeat;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalSetOperation;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalTopN;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalWindow;
 import org.apache.doris.nereids.trees.plans.physical.RuntimeFilter;
-import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
 import org.apache.doris.nereids.types.coercion.NumericType;
 import org.apache.doris.nereids.util.ExpressionUtils;
+import org.apache.doris.nereids.util.PlanUtils;
 import org.apache.doris.qe.ConnectContext;
 import org.apache.doris.thrift.TMinMaxRuntimeFilterType;
 import org.apache.doris.thrift.TRuntimeFilterType;
@@ -56,7 +55,7 @@ import java.util.Set;
  * Rewrites probeExpr through Projects and SetOperations, expands through join 
conditions,
  * and creates RuntimeFilter at scan nodes when probeExpr resolves to a scan 
slot.
  */
-public class RuntimeFilterPushDownVisitor extends PlanVisitor<Boolean, 
PushDownContext> {
+public class RuntimeFilterPushDownVisitor extends 
AbstractRuntimeFilterPushDownVisitor<PushDownContext> {
 
     /**
      * PushDownContext carries the information needed to push a runtime filter 
down the plan tree.
@@ -145,12 +144,17 @@ public class RuntimeFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownC
         }
     }
 
+    @Override
+    protected Expression getProbeExpression(PushDownContext ctx) {
+        return ctx.probeExpr;
+    }
+
     @Override
     public Boolean visit(Plan plan, PushDownContext ctx) {
         boolean pushed = false;
         for (Plan child : plan.children()) {
             if 
(child.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())) {
-                pushed |= child.accept(this, ctx);
+                pushed |= pushDown(child, ctx);
             }
         }
         return pushed;
@@ -286,18 +290,24 @@ public class RuntimeFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownC
         Plan rightNode = join.child(1);
         if (leftNode.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())
                 && canPushThroughJoinChild(join, true, ctx)) {
-            pushed |= leftNode.accept(this, ctx);
+            pushed |= pushDown(leftNode, ctx);
         }
         if (rightNode.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())
                 && canPushThroughJoinChild(join, false, ctx)) {
-            pushed |= rightNode.accept(this, ctx);
+            pushed |= pushDown(rightNode, ctx);
         }
 
-        // Expand through join conditions at non-builder inner/semi joins
+        // Outer joins only propagate a parent's ordinary join RF from the 
preserved side.
+        // Decoupled RFs do not carry the parent equality here, so leave them 
out of this expansion.
+        boolean expandByOuterJoin = !join.isMarkJoin()
+                && ctx.exprOrder >= 0 && ctx.builderNode instanceof 
PhysicalHashJoin
+                && (join.getJoinType().isLeftOuterJoin() || 
join.getJoinType().isRightOuterJoin());
+        // Expand through join conditions at non-builder joins.
         if (!join.equals(ctx.builderNode)
                 && ConnectContext.get() != null
                 && 
ConnectContext.get().getSessionVariable().expandRuntimeFilterByInnerJoin
-                && (join.getJoinType() == JoinType.INNER_JOIN || 
join.getJoinType().isSemiJoin())) {
+                && (join.getJoinType() == JoinType.INNER_JOIN || 
join.getJoinType().isSemiJoin()
+                        || expandByOuterJoin)) {
             for (Expression expr : join.getHashJoinConjuncts()) {
                 EqualPredicate equalTo = (EqualPredicate) expr;
                 Expression newTarget = null;
@@ -308,12 +318,31 @@ public class RuntimeFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownC
                 }
                 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)
+                                || 
!ctx.srcExpr.getDataType().equals(ctx.probeExpr.getDataType())
+                                || 
!ctx.probeExpr.getDataType().equals(newTarget.getDataType())
+                                || 
!preserved.getOutputSet().contains(ctx.probeExpr)
+                                || 
!nonPreserved.getOutputSet().contains(newTarget)) {
+                            continue;
+                        }
+                    }
                     PushDownContext expanded = 
ctx.withNewProbeExpression(newTarget);
                     if 
(leftNode.getOutputSet().containsAll(newTarget.getInputSlots())) {
-                        pushed |= leftNode.accept(this, expanded);
+                        pushed |= pushDown(leftNode, expanded);
                     }
                     if 
(rightNode.getOutputSet().containsAll(newTarget.getInputSlots())) {
-                        pushed |= rightNode.accept(this, expanded);
+                        pushed |= pushDown(rightNode, expanded);
                     }
                 }
             }
@@ -351,11 +380,11 @@ public class RuntimeFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownC
         Plan right = join.right();
         if (left.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())
                 && canPushThroughJoinChild(join, true, ctx)) {
-            pushed |= left.accept(this, ctx);
+            pushed |= pushDown(left, ctx);
         }
         if (right.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())
                 && canPushThroughJoinChild(join, false, ctx)) {
-            pushed |= right.accept(this, ctx);
+            pushed |= pushDown(right, ctx);
         }
         return pushed;
     }
@@ -409,7 +438,7 @@ public class RuntimeFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownC
         Expression newProbeExpr = ctx.probeExpr.rewriteDownShortCircuit(
                 e -> replaceMap.getOrDefault(e, e));
         if (newProbeExpr.getInputSlots().size() == 1) {
-            return project.child().accept(this, 
ctx.withNewProbeExpression(newProbeExpr));
+            return pushDown(project.child(), 
ctx.withNewProbeExpression(newProbeExpr));
         }
         return false;
     }
@@ -433,32 +462,12 @@ public class RuntimeFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownC
             Expression newProbeExpr = ctx.probeExpr.rewriteDownShortCircuit(
                     e -> replaceMap.getOrDefault(e, e));
             if (newProbeExpr.getInputSlots().size() == 1) {
-                pushedDown |= setOperation.child(i).accept(this, 
ctx.withNewProbeExpression(newProbeExpr));
+                pushedDown |= pushDown(setOperation.child(i), 
ctx.withNewProbeExpression(newProbeExpr));
             }
         }
         return pushedDown;
     }
 
-    @Override
-    public Boolean visitPhysicalRepeat(PhysicalRepeat<? extends Plan> repeat, 
PushDownContext ctx) {
-        if (!repeat.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())) 
{
-            return false;
-        }
-        // Only push through Repeat if the probe slot appears in ALL grouping 
sets.
-        // A slot absent from a grouping set is erased to NULL for rows of 
that group,
-        // so filtering on it would incorrectly discard needed rows.
-        Set<Expression> commonGroupingExprs = 
repeat.getCommonGroupingSetExpressions();
-        if (!commonGroupingExprs.containsAll(ctx.probeExpr.getInputSlots())) {
-            return false;
-        }
-        return repeat.child().accept(this, ctx);
-    }
-
-    @Override
-    public Boolean visitPhysicalTopN(PhysicalTopN<? extends Plan> topN, 
PushDownContext ctx) {
-        return false;
-    }
-
     @Override
     public Boolean visitPhysicalWindow(PhysicalWindow<? extends Plan> window, 
PushDownContext ctx) {
         if (!window.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())) 
{
@@ -467,7 +476,7 @@ public class RuntimeFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownC
 
         Set<SlotReference> commonPartitionKeys = 
window.getCommonPartitionKeyFromWindowExpressions();
         if (commonPartitionKeys.containsAll(ctx.probeExpr.getInputSlots())) {
-            return window.child().accept(this, ctx);
+            return pushDown(window.child(), ctx);
         }
         return false;
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopNScanOpt.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopNScanOpt.java
index 705562a45b3..bd35f64c6dd 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopNScanOpt.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopNScanOpt.java
@@ -21,7 +21,6 @@ import org.apache.doris.nereids.CascadesContext;
 import 
org.apache.doris.nereids.processor.post.TopnFilterPushDownVisitor.PushDownContext;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.SortPhase;
-import org.apache.doris.nereids.trees.plans.algebra.TopN;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalTopN;
 import org.apache.doris.nereids.types.DataType;
 
@@ -43,20 +42,18 @@ public class TopNScanOpt extends PlanPostProcessor {
             TopnFilterPushDownVisitor.PushDownContext pushdownContext = new 
PushDownContext(topN,
                     topN.getOrderKeys().get(0).getExpr(),
                     topN.getOrderKeys().get(0).isNullFirst());
-            topN.accept(pusher, pushdownContext);
+            pusher.pushDown(topN.child(), pushdownContext);
         }
         return topN;
     }
 
-    boolean checkTopN(TopN topN) {
-        if (!(topN instanceof PhysicalTopN)) {
-            return false;
-        }
-        if (((PhysicalTopN) topN).getSortPhase() != SortPhase.LOCAL_SORT) {
+    private boolean checkTopN(PhysicalTopN<?> topN) {
+        if (topN.getSortPhase() != SortPhase.LOCAL_SORT) {
             return false;
         }
 
-        if (topN.getOrderKeys().isEmpty()) {
+        if (topN.getOrderKeys().isEmpty()
+                || 
AbstractRuntimeFilterPushDownVisitor.hasSensitiveExpressions(topN)) {
             return false;
         }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopnFilterPushDownVisitor.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopnFilterPushDownVisitor.java
index 197f63456c1..971606ad64b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopnFilterPushDownVisitor.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopnFilterPushDownVisitor.java
@@ -27,7 +27,6 @@ import 
org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitors;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.algebra.TopN;
 import org.apache.doris.nereids.trees.plans.algebra.Union;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalAssertNumRows;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalCTEAnchor;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalCTEProducer;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalFileScan;
@@ -38,11 +37,8 @@ import 
org.apache.doris.nereids.trees.plans.physical.PhysicalOdbcScan;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalOlapScan;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalProject;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalRelation;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalRepeat;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalSetOperation;
-import org.apache.doris.nereids.trees.plans.physical.PhysicalTopN;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalWindow;
-import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
 import org.apache.doris.nereids.util.ExpressionUtils;
 import org.apache.doris.qe.ConnectContext;
 
@@ -54,7 +50,7 @@ import java.util.Map;
 /**
  * push down topn filter
  */
-public class TopnFilterPushDownVisitor extends PlanVisitor<Boolean, 
PushDownContext> {
+public class TopnFilterPushDownVisitor extends 
AbstractRuntimeFilterPushDownVisitor<PushDownContext> {
 
     private final TopnFilterContext topnFilterContext;
 
@@ -82,13 +78,18 @@ public class TopnFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownCont
 
     }
 
+    @Override
+    protected Expression getProbeExpression(PushDownContext ctx) {
+        return ctx.probeExpr;
+    }
+
     @Override
     public Boolean visit(Plan plan, PushDownContext ctx) {
         // A bound on a grouping key can exclude whole groups. Stopping at 
unlisted operators
         // here would disable existing scan filters below aggregates and their 
join inputs.
         boolean pushed = false;
         for (Plan child : plan.children()) {
-            pushed |= child.accept(this, ctx);
+            pushed |= pushDown(child, ctx);
         }
         return pushed;
     }
@@ -109,7 +110,7 @@ public class TopnFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownCont
             Expression newProbeExpr = 
ctx.probeExpr.accept(ExpressionVisitors.EXPRESSION_MAP_REPLACER, replaceMap);
             ctxProjectProbeExpr = ctx.withNewProbeExpression(newProbeExpr);
         }
-        return project.child().accept(this, ctxProjectProbeExpr);
+        return pushDown(project.child(), ctxProjectProbeExpr);
     }
 
     @Override
@@ -143,7 +144,7 @@ public class TopnFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownCont
             Expression newProbeExpr = 
ctx.probeExpr.accept(ExpressionVisitors.EXPRESSION_MAP_REPLACER,
                     replaceMap);
             PushDownContext childPushDownContext = 
ctx.withNewProbeExpression(newProbeExpr);
-            return child.accept(this, childPushDownContext);
+            return pushDown(child, childPushDownContext);
         }
         return false;
     }
@@ -160,32 +161,6 @@ public class TopnFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownCont
         return false;
     }
 
-    @Override
-    public Boolean visitPhysicalAssertNumRows(
-            PhysicalAssertNumRows<? extends Plan> assertNumRows, 
PushDownContext ctx) {
-        // Filtering its input can hide a cardinality error or make a scalar 
subquery
-        // synthesize a NULL row that did not exist before filtering.
-        return false;
-    }
-
-    @Override
-    public Boolean visitPhysicalTopN(PhysicalTopN<? extends Plan> topn, 
PushDownContext ctx) {
-        if (topn.equals(ctx.topn)) {
-            return topn.child().accept(this, ctx);
-        }
-        return false;
-    }
-
-    @Override
-    public Boolean visitPhysicalRepeat(PhysicalRepeat<? extends Plan> repeat, 
PushDownContext ctx) {
-        // Repeat erases grouping keys absent from a grouping set to NULL. 
Filtering those
-        // keys before Repeat can discard rows that still contribute to the 
NULL group.
-        if 
(!repeat.getCommonGroupingSetExpressions().containsAll(ctx.probeExpr.getInputSlots()))
 {
-            return false;
-        }
-        return repeat.child().accept(this, ctx);
-    }
-
     @Override
     public Boolean visitPhysicalWindow(PhysicalWindow<? extends Plan> window, 
PushDownContext ctx) {
         return false;
@@ -223,7 +198,7 @@ public class TopnFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownCont
         }
         if 
(join.left().getOutputSet().containsAll(ctx.probeExpr.getInputSlots())) {
             PushDownContext childPushDownContext = 
adjustProbeExprNullableThroughOuterJoin(join.left(), ctx);
-            return join.left().accept(this, childPushDownContext);
+            return pushDown(join.left(), childPushDownContext);
         }
         if 
(join.right().getOutputSet().containsAll(ctx.probeExpr.getInputSlots())) {
             // expand expr to the other side of hash join condition:
@@ -235,7 +210,7 @@ public class TopnFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownCont
                     PushDownContext ctxOnLeftChild = 
ctx.withNewProbeExpression(conj.child(0));
                     PushDownContext childPushDownContext = 
adjustProbeExprNullableThroughOuterJoin(join.left(),
                             ctxOnLeftChild);
-                    return join.left().accept(this, childPushDownContext);
+                    return pushDown(join.left(), childPushDownContext);
                 }
             }
         }
@@ -256,7 +231,7 @@ public class TopnFilterPushDownVisitor extends 
PlanVisitor<Boolean, PushDownCont
         }
         // push to left child. right child is blocking operator, do not need 
topn-filter
         if 
(join.left().getOutputSet().containsAll(ctx.probeExpr.getInputSlots())) {
-            return join.left().accept(this, ctx);
+            return pushDown(join.left(), ctx);
         }
         return false;
     }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/RuntimeFilterTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/RuntimeFilterTest.java
index 57f6aac9c74..e84b3fa365d 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/RuntimeFilterTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/RuntimeFilterTest.java
@@ -29,7 +29,9 @@ import org.apache.doris.nereids.parser.NereidsParser;
 import org.apache.doris.nereids.processor.post.PlanPostProcessors;
 import org.apache.doris.nereids.processor.post.RuntimeFilterContext;
 import org.apache.doris.nereids.processor.post.RuntimeFilterGenerator;
+import org.apache.doris.nereids.processor.post.RuntimeFilterPushDownVisitor;
 import 
org.apache.doris.nereids.processor.post.RuntimeFilterPushDownVisitor.PushDownContext;
+import org.apache.doris.nereids.properties.OrderKey;
 import org.apache.doris.nereids.properties.PhysicalProperties;
 import org.apache.doris.nereids.trees.expressions.Add;
 import org.apache.doris.nereids.trees.expressions.Alias;
@@ -47,7 +49,9 @@ import 
org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
 import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
 import org.apache.doris.nereids.trees.plans.DistributeType;
 import org.apache.doris.nereids.trees.plans.JoinType;
+import org.apache.doris.nereids.trees.plans.PartitionTopnPhase;
 import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.WindowFuncType;
 import org.apache.doris.nereids.trees.plans.commands.ExplainCommand;
 import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
 import org.apache.doris.nereids.trees.plans.physical.AbstractPhysicalPlan;
@@ -55,6 +59,7 @@ import 
org.apache.doris.nereids.trees.plans.physical.PhysicalCTEConsumer;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalCTEProducer;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalHashJoin;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalOlapScan;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalPartitionTopN;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalPlan;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalProject;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalRelation;
@@ -271,6 +276,168 @@ public class RuntimeFilterTest extends SSBTestBase {
                 Pair.of("s_suppkey", "c_custkey"), Pair.of("c_custkey", 
"lo_custkey")));
     }
 
+    @Test
+    public void testExpandRuntimeFilterThroughLeftOuterJoin() {
+        try {
+            for (String condition : ImmutableList.of("lo_orderdate = 
d_datekey", "d_datekey = lo_orderdate")) {
+                String sql = "select * from lineorder left join dates on " + 
condition
+                        + " inner join customer on lo_orderdate = c_custkey";
+                Assertions.assertEquals(1, 
getRuntimeFilters(sql).get().size());
+
+                
connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin = true;
+                RuntimeFilterContext context = getRuntimeFilterContext(sql);
+                checkRuntimeFilterExprs(context.getNereidsRuntimeFilter(), 
ImmutableList.of(
+                        Pair.of("c_custkey", "lo_orderdate"), 
Pair.of("c_custkey", "d_datekey")));
+                Assertions.assertEquals(1, context.getLegacyFilters().size());
+                Assertions.assertEquals(2, 
context.getLegacyFilters().get(0).toThrift().getPlanIdToTargetExprSize());
+                
connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin = false;
+            }
+        } finally {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= false;
+        }
+    }
+
+    @Test
+    public void testExpandRuntimeFilterThroughRightOuterJoin() {
+        try {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= true;
+            for (String condition : ImmutableList.of("lo_orderdate = 
d_datekey", "d_datekey = lo_orderdate")) {
+                List<RuntimeFilter> filters = getRuntimeFilters(
+                        "select * from lineorder right join dates on " + 
condition
+                                + " inner join customer on d_datekey = 
c_custkey").get().stream()
+                        .filter(rf -> 
rf.getSrcExpr().toSql().equals("c_custkey"))
+                        .collect(Collectors.toList());
+                checkRuntimeFilterExprs(filters, ImmutableList.of(
+                        Pair.of("c_custkey", "d_datekey"), 
Pair.of("c_custkey", "lo_orderdate")));
+            }
+        } finally {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= false;
+        }
+    }
+
+    @Test
+    public void testExpandRuntimeFilterThroughNestedOuterJoins() {
+        try {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= true;
+            List<RuntimeFilter> filters = getRuntimeFilters(
+                    "select * from lineorder left join dates on lo_orderdate = 
d_datekey"
+                            + " left join supplier on lo_orderdate = s_suppkey"
+                            + " inner join customer on lo_orderdate = 
c_custkey").get();
+            checkRuntimeFilterExprs(filters, ImmutableList.of(
+                    Pair.of("c_custkey", "lo_orderdate"), Pair.of("c_custkey", 
"d_datekey"),
+                    Pair.of("c_custkey", "s_suppkey")));
+        } finally {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= false;
+        }
+    }
+
+    @Test
+    public void testDoNotExpandOuterJoinRuntimeFilterThroughExpressions() {
+        try {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= true;
+            for (String condition : ImmutableList.of("lo_orderdate = d_datekey 
+ 1",
+                    "lo_orderdate + 1 = d_datekey")) {
+                List<RuntimeFilter> filters = getRuntimeFilters(
+                        "select * from lineorder left join dates on " + 
condition
+                                + " inner join customer on lo_orderdate = 
c_custkey").get();
+                Assertions.assertEquals(1, filters.size(), condition);
+                checkRuntimeFilterExprs(filters, 
ImmutableList.of(Pair.of("c_custkey", "lo_orderdate")));
+            }
+        } finally {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= false;
+        }
+    }
+
+    @Test
+    public void testDoNotExpandOuterJoinRuntimeFilterThroughNullSafeEquality() 
{
+        try {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= true;
+            for (boolean nullSafeBuilder : ImmutableList.of(false, true)) {
+                PhysicalHashJoin<?, ?> baseJoin = 
findFirstHashJoin(planAfterPostProcess(
+                        "select * from lineorder left join dates on 
lo_orderdate = d_datekey"));
+                EqualTo condition = (EqualTo) 
baseJoin.getHashJoinConjuncts().get(0);
+                // Use physical predicates: SQL rewrites may simplify <=> on 
NOT NULL keys to =.
+                Expression lowerCondition = nullSafeBuilder ? condition
+                        : new NullSafeEqual(condition.left(), 
condition.right());
+                PhysicalHashJoin<?, ?> join = new 
PhysicalHashJoin<>(JoinType.LEFT_OUTER_JOIN,
+                        ImmutableList.of(lowerCondition), ImmutableList.of(),
+                        new DistributeHint(DistributeType.NONE), 
Optional.empty(), null,
+                        baseJoin.left(), baseJoin.right());
+                RuntimeFilterContext context = new 
RuntimeFilterContext(connectContext.getSessionVariable(),
+                        RuntimeFilterId.createGenerator());
+                SlotReference source = new SlotReference("source_key", 
condition.left().getDataType());
+                PushDownContext pushDown = 
PushDownContext.createPushDownContext(context,
+                        newHashJoinBuilder(nullSafeBuilder), source, 
condition.left(),
+                        TRuntimeFilterType.IN_OR_BLOOM, false, 1, 0);
+                new RuntimeFilterPushDownVisitor().pushDown(join, pushDown);
+                Assertions.assertEquals(nullSafeBuilder ? 0 : 1, 
context.getNereidsRuntimeFilter().size());
+            }
+        } finally {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= false;
+        }
+    }
+
+    @Test
+    public void testDoNotExpandOuterJoinRuntimeFilterFromNonPreservedSide() {
+        try {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= true;
+            for (JoinType joinType : 
ImmutableList.of(JoinType.LEFT_OUTER_JOIN, JoinType.RIGHT_OUTER_JOIN,
+                    JoinType.FULL_OUTER_JOIN)) {
+                PhysicalHashJoin<?, ?> baseJoin = 
findFirstHashJoin(planAfterPostProcess(
+                        "select * from lineorder left join dates on 
lo_orderdate = d_datekey"));
+                EqualTo condition = (EqualTo) 
baseJoin.getHashJoinConjuncts().get(0);
+                PhysicalHashJoin<?, ?> join = new PhysicalHashJoin<>(joinType, 
ImmutableList.of(condition),
+                        ImmutableList.of(), new 
DistributeHint(DistributeType.NONE), Optional.empty(), null,
+                        baseJoin.left(), baseJoin.right());
+                Expression probe = joinType.isRightOuterJoin() ? 
condition.left() : condition.right();
+                RuntimeFilterContext context = new 
RuntimeFilterContext(connectContext.getSessionVariable(),
+                        RuntimeFilterId.createGenerator());
+                SlotReference source = new SlotReference("source_key", 
probe.getDataType());
+                PushDownContext pushDown = 
PushDownContext.createPushDownContext(context,
+                        newHashJoinBuilder(false), source, probe, 
TRuntimeFilterType.IN_OR_BLOOM,
+                        false, 1, 0);
+                new RuntimeFilterPushDownVisitor().pushDown(join, pushDown);
+                List<RuntimeFilter> filters = 
context.getNereidsRuntimeFilter();
+                Assertions.assertEquals(1, filters.size());
+                Assertions.assertEquals(probe, 
filters.get(0).getTargetExpression());
+            }
+        } finally {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= false;
+        }
+    }
+
+    @Test
+    public void testOuterJoinExpansionKeepsNonBlockingRequirement() {
+        try {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= true;
+            for (JoinType joinType : 
ImmutableList.of(JoinType.LEFT_OUTER_JOIN, JoinType.RIGHT_OUTER_JOIN)) {
+                PhysicalHashJoin<?, ?> baseJoin = 
findFirstHashJoin(planAfterPostProcess(
+                        "select * from lineorder left join dates on 
lo_orderdate = d_datekey"));
+                EqualTo condition = (EqualTo) 
baseJoin.getHashJoinConjuncts().get(0);
+                PhysicalHashJoin<?, ?> join = new PhysicalHashJoin<>(joinType, 
ImmutableList.of(condition),
+                        ImmutableList.of(), new 
DistributeHint(DistributeType.NONE), Optional.empty(), null,
+                        baseJoin.left(), baseJoin.right());
+                Expression probe = joinType.isLeftOuterJoin() ? 
condition.left() : condition.right();
+                RuntimeFilterContext context = new 
RuntimeFilterContext(connectContext.getSessionVariable(),
+                        RuntimeFilterId.createGenerator());
+                SlotReference source = new SlotReference("source_key", 
probe.getDataType());
+                AbstractPhysicalPlan builder = newHashJoinBuilder(false);
+                PushDownContext pushDown = 
PushDownContext.createPushDownContext(context, builder,
+                        source, probe, TRuntimeFilterType.IN_OR_BLOOM, false, 
1, 0).withNonBlocking(true);
+                new RuntimeFilterPushDownVisitor().pushDown(join, pushDown);
+                List<RuntimeFilter> filters = 
context.getNereidsRuntimeFilter();
+                Assertions.assertEquals(2, filters.size());
+                for (RuntimeFilter filter : filters) {
+                    Assertions.assertSame(builder, filter.getBuilderNode());
+                    Assertions.assertEquals(source, filter.getSrcExpr());
+                    Assertions.assertTrue(filter.isNonBlocking());
+                }
+            }
+        } finally {
+            connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin 
= false;
+        }
+    }
+
     @Test
     public void 
testDoNotPushDownNonNullPropagatingRuntimeFilterThroughOuterJoin() {
         String sql = "select * from lineorder left outer join customer on 
lo_custkey = c_custkey"
@@ -392,7 +559,7 @@ public class RuntimeFilterTest extends SSBTestBase {
     }
 
     @Test
-    public void testPushDownThroughUnsupportedJoinType() {
+    public void testPushDownThroughOuterJoinWithExpansion() {
         String sql = "select c_custkey from (select c_custkey from (select 
lo_custkey from lineorder inner join dates"
                 + " on lo_orderdate = d_datekey) a"
                 + " inner join (select c_custkey from customer left outer join 
supplier on c_custkey = s_suppkey) b"
@@ -403,8 +570,9 @@ public class RuntimeFilterTest extends SSBTestBase {
 
         connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin = 
true;
         filters = getRuntimeFilters(sql).get();
-        // Expansion through inner joins creates additional RFs
-        Assertions.assertEquals(5, filters.size());
+        // Expand to lineorder through the inner join and to supplier through 
the left outer join.
+        Assertions.assertEquals(6, filters.size());
+        Assertions.assertTrue(filters.stream().anyMatch(rf -> 
rf.getTargetSlot().getName().equals("s_suppkey")));
         connectContext.getSessionVariable().expandRuntimeFilterByInnerJoin = 
false;
 
     }
@@ -550,6 +718,31 @@ public class RuntimeFilterTest extends SSBTestBase {
         Assertions.assertEquals(0, filters.size());
     }
 
+    @Test
+    public void testRuntimeFilterThroughPartitionTopN() {
+        PhysicalOlapScan scan = (PhysicalOlapScan) planAfterPostProcess(
+                "SELECT lo_partkey, lo_custkey FROM lineorder")
+                .collect(PhysicalOlapScan.class::isInstance).iterator().next();
+        Slot partitionKey = scan.getOutput().get(0);
+        Slot orderKey = scan.getOutput().get(1);
+        for (boolean globalLimit : ImmutableList.of(false, true)) {
+            PhysicalPartitionTopN<PhysicalOlapScan> partitionTopN = new 
PhysicalPartitionTopN<>(
+                    WindowFuncType.ROW_NUMBER, ImmutableList.of(partitionKey),
+                    ImmutableList.of(new OrderKey(orderKey, true, true)), 
globalLimit, 1,
+                    PartitionTopnPhase.TWO_PHASE_GLOBAL_PTOPN, 
scan.getLogicalProperties(), scan);
+            for (Slot probe : ImmutableList.of(partitionKey, orderKey)) {
+                RuntimeFilterContext context = new 
RuntimeFilterContext(connectContext.getSessionVariable(),
+                        RuntimeFilterId.createGenerator());
+                PushDownContext pushDown = 
PushDownContext.createPushDownContext(context,
+                        newHashJoinBuilder(false), new 
SlotReference("source_key", probe.getDataType()),
+                        probe, TRuntimeFilterType.IN_OR_BLOOM, false, 1, 0);
+                boolean expected = !globalLimit && probe.equals(partitionKey);
+                Assertions.assertEquals(expected, new 
RuntimeFilterPushDownVisitor().pushDown(partitionTopN, pushDown));
+                Assertions.assertEquals(expected ? 1 : 0, 
context.getNereidsRuntimeFilter().size());
+            }
+        }
+    }
+
     @Test
     public void testRuntimeFilterShapeInfoWithoutBrackets() {
         String sql = "SELECT * FROM lineorder JOIN customer ON lo_custkey = 
c_custkey";
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/TopNRuntimeFilterTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/TopNRuntimeFilterTest.java
index 837aa1b45eb..b0ab4afc640 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/TopNRuntimeFilterTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/postprocess/TopNRuntimeFilterTest.java
@@ -86,9 +86,7 @@ public class TopNRuntimeFilterTest extends SSBTestBase 
implements MemoPatternMat
         double previousRatio = 
connectContext.getSessionVariable().topnFilterRatio;
         connectContext.getSessionVariable().topnFilterRatio = 1000000;
         try {
-            for (String expression : List.of("weeks_add(d, 1)", 
"from_microsecond(ts)",
-                    "cast(ts AS TINYINT)", "assert_true(k < 3, 'out of 
range')")) {
-                // A row excluded by the leading key need not evaluate its 
secondary expression.
+            for (String expression : List.of("weeks_add(d, 1)", 
"from_microsecond(ts)", "cast(ts AS TINYINT)")) {
                 PlanChecker checker = PlanChecker.from(connectContext)
                         .analyze("SELECT k, " + expression + " AS v FROM 
topn_safety "
                                 + "ORDER BY k, v LIMIT 3")
@@ -103,6 +101,24 @@ public class TopNRuntimeFilterTest extends SSBTestBase 
implements MemoPatternMat
         }
     }
 
+    @Test
+    public void testTopNFilterStopsAtNonMovableSecondaryExpression() {
+        double previousRatio = 
connectContext.getSessionVariable().topnFilterRatio;
+        connectContext.getSessionVariable().topnFilterRatio = 1000000;
+        try {
+            PlanChecker checker = PlanChecker.from(connectContext)
+                    .analyze("SELECT k, assert_true(k < 3, 'out of range') AS 
v FROM topn_safety "
+                            + "ORDER BY k, v LIMIT 3")
+                    .rewrite().implement();
+            PhysicalPlan plan = new 
PlanPostProcessors(checker.getCascadesContext())
+                    .process(checker.getPhysicalPlan());
+            
Assertions.assertTrue(checker.getCascadesContext().getTopnFilterContext()
+                    .getTopnFilters().isEmpty(), plan.treeString());
+        } finally {
+            connectContext.getSessionVariable().topnFilterRatio = 
previousRatio;
+        }
+    }
+
     @Test
     public void testTopNFilterCrossesGroupedKeyAggregation() {
         double previousRatio = 
connectContext.getSessionVariable().topnFilterRatio;
@@ -208,10 +224,10 @@ public class TopNRuntimeFilterTest extends SSBTestBase 
implements MemoPatternMat
                         TopnFilterContext filters = new TopnFilterContext();
                         TopnFilterPushDownVisitor visitor = new 
TopnFilterPushDownVisitor(filters);
                         // Visit Assert directly so the test does not depend 
on the scalar join's probe side.
-                        Assertions.assertFalse(assertion.accept(visitor, 
context), sql);
+                        Assertions.assertFalse(visitor.pushDown(assertion, 
context), sql);
                         
Assertions.assertTrue(filters.getTopnFilters().isEmpty(), sql);
                         // The child accepts this filter; Assert must protect 
its row count and empty-row behavior.
-                        
Assertions.assertTrue(assertion.child().accept(visitor, context), sql);
+                        
Assertions.assertTrue(visitor.pushDown(assertion.child(), context), sql);
                         
Assertions.assertFalse(filters.getTopnFilters().isEmpty(), sql);
                     }
                 }
diff --git 
a/regression-test/data/query_p0/runtime_filter/outer_join_runtime_filter.out 
b/regression-test/data/query_p0/runtime_filter/outer_join_runtime_filter.out
new file mode 100644
index 00000000000..36ad17fdc58
--- /dev/null
+++ b/regression-test/data/query_p0/runtime_filter/outer_join_runtime_filter.out
@@ -0,0 +1,206 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !left_false --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !right_false --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !nested_false --
+1      1       11      100     1000
+1      1       11      101     1000
+1      1       111     100     1000
+1      1       111     101     1000
+2      2       22      202     2000
+3      3       33      \N      3000
+
+-- !alias_false --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !shared_cte_false --
+1      1       11      100     100
+1      1       11      100     101
+1      1       11      101     100
+1      1       11      101     101
+1      1       111     100     100
+1      1       111     100     101
+1      1       111     101     100
+1      1       111     101     101
+2      2       22      202     202
+3      3       33      \N      \N
+
+-- !null_safe_outer_false --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !null_safe_parent_false --
+\N     1       1       \N
+1      \N      10      \N
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !coalesce_false --
+1      \N      10      \N
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+1      2       12      \N
+2      2       22      202
+
+-- !left_true --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !right_true --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !nested_true --
+1      1       11      100     1000
+1      1       11      101     1000
+1      1       111     100     1000
+1      1       111     101     1000
+2      2       22      202     2000
+3      3       33      \N      3000
+
+-- !alias_true --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !shared_cte_true --
+1      1       11      100     100
+1      1       11      100     101
+1      1       11      101     100
+1      1       11      101     101
+1      1       111     100     100
+1      1       111     100     101
+1      1       111     101     100
+1      1       111     101     101
+2      2       22      202     202
+3      3       33      \N      \N
+
+-- !null_safe_outer_true --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !null_safe_parent_true --
+\N     1       1       \N
+1      \N      10      \N
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !coalesce_true --
+1      \N      10      \N
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+1      2       12      \N
+2      2       22      202
+
+-- !left_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((a.k = e.k) and (a.org = 
e.org)) otherCondition=() build RFs:RF0 org->org;RF1 org->org;RF2 k->k;RF3 k->k
+------PhysicalProject
+--------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((a.k = b.k) and 
(a.org = b.org)) otherCondition=()
+----------PhysicalOlapScan[outer_rf_contact(a)] apply RFs: RF0 RF2
+----------PhysicalOlapScan[outer_rf_address(b)] apply RFs: RF1 RF3
+------PhysicalOlapScan[outer_rf_event(e)]
+
+-- !nested_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((a.k = e.k) and (a.org = 
e.org)) otherCondition=() build RFs:RF0 org->org;RF1 org->org;RF2 org->org;RF3 
k->k;RF4 k->k;RF5 k->k
+------PhysicalProject
+--------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((a.k = p.k) and 
(a.org = p.org)) otherCondition=()
+----------PhysicalProject
+------------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((b.k = a.k) and 
(b.org = a.org)) otherCondition=()
+--------------PhysicalOlapScan[outer_rf_contact(a)] apply RFs: RF0 RF3
+--------------PhysicalOlapScan[outer_rf_address(b)] apply RFs: RF1 RF4
+----------PhysicalOlapScan[outer_rf_phone(p)] apply RFs: RF2 RF5
+------PhysicalOlapScan[outer_rf_event(e)]
+
+-- !filter_type_1 --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !filter_type_2 --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !filter_type_4 --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !filter_type_8 --
+1      1       11      100
+1      1       11      101
+1      1       111     100
+1      1       111     101
+2      2       22      202
+3      3       33      \N
+
+-- !empty_non_preserved --
+1      1       11      \N
+1      1       111     \N
+2      2       22      \N
+3      3       33      \N
+
+-- !empty_producer --
+
diff --git 
a/regression-test/data/query_p0/runtime_filter/outer_join_runtime_filter_row_count.out
 
b/regression-test/data/query_p0/runtime_filter/outer_join_runtime_filter_row_count.out
new file mode 100644
index 00000000000..05bc89fdefc
--- /dev/null
+++ 
b/regression-test/data/query_p0/runtime_filter/outer_join_runtime_filter_row_count.out
@@ -0,0 +1,119 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !scalar_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((l.k = e.k)) 
otherCondition=() build RFs:RF0 k->k
+------PhysicalProject
+--------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((l.k = r.k)) 
otherCondition=()
+----------PhysicalOlapScan[outer_rf_row_count_left(l)] apply RFs: RF0
+----------NestedLoopJoin[CROSS_JOIN]
+------------PhysicalOlapScan[outer_rf_row_count_payload(d)]
+------------PhysicalAssertNumRows
+--------------PhysicalDistribute[DistributionSpecGather]
+----------------PhysicalProject
+------------------PhysicalOlapScan[outer_rf_row_count_right(r)]
+------PhysicalOlapScan[outer_rf_row_count_build(e)]
+
+-- !limit_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((l.k = e.k)) 
otherCondition=() build RFs:RF0 k->k
+------PhysicalProject
+--------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((l.k = r.k)) 
otherCondition=()
+----------PhysicalOlapScan[outer_rf_row_count_left(l)] apply RFs: RF0
+----------PhysicalLimit[GLOBAL]
+------------PhysicalLimit[LOCAL]
+--------------PhysicalQuickSort[MERGE_SORT]
+----------------PhysicalDistribute[DistributionSpecGather]
+------------------PhysicalQuickSort[LOCAL_SORT]
+--------------------PhysicalOlapScan[outer_rf_row_count_right]
+------PhysicalOlapScan[outer_rf_row_count_build(e)]
+
+-- !limit_result --
+2      \N
+
+-- !project_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((l.k = e.k)) 
otherCondition=() build RFs:RF0 k->k
+------PhysicalProject
+--------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((l.k = r.k)) 
otherCondition=()
+----------PhysicalOlapScan[outer_rf_row_count_left(l)] apply RFs: RF0
+----------PhysicalProject
+------------PhysicalOlapScan[outer_rf_row_count_right]
+------PhysicalOlapScan[outer_rf_row_count_build(e)]
+
+-- !filter_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((l.k = e.k)) 
otherCondition=() build RFs:RF0 k->k
+------PhysicalProject
+--------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((l.k = r.k)) 
otherCondition=()
+----------PhysicalOlapScan[outer_rf_row_count_left(l)] apply RFs: RF0
+----------PhysicalProject
+------------filter(assert_true((outer_rf_row_count_right.v > 10), 'bad'))
+--------------PhysicalOlapScan[outer_rf_row_count_right]
+------PhysicalOlapScan[outer_rf_row_count_build(e)]
+
+-- !window_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((l.k = e.k)) 
otherCondition=() build RFs:RF0 k->k
+------PhysicalProject
+--------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((l.k = r.k)) 
otherCondition=()
+----------PhysicalOlapScan[outer_rf_row_count_left(l)] apply RFs: RF0
+----------PhysicalProject
+------------PhysicalWindow
+--------------PhysicalQuickSort[LOCAL_SORT]
+----------------PhysicalProject
+------------------PhysicalOlapScan[outer_rf_row_count_right]
+------PhysicalOlapScan[outer_rf_row_count_build(e)]
+
+-- !aggregate_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((l.k = e.k)) 
otherCondition=() build RFs:RF0 k->k
+------PhysicalProject
+--------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((l.k = r.k)) 
otherCondition=()
+----------PhysicalOlapScan[outer_rf_row_count_left(l)] apply RFs: RF0
+----------hashAgg[GLOBAL]
+------------PhysicalOlapScan[outer_rf_row_count_right]
+------PhysicalOlapScan[outer_rf_row_count_build(e)]
+
+-- !sort_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((l.k = e.k)) 
otherCondition=() build RFs:RF0 k->k
+------PhysicalProject
+--------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((l.k = r.k)) 
otherCondition=()
+----------PhysicalOlapScan[outer_rf_row_count_left(l)] apply RFs: RF0
+----------PhysicalProject
+------------PhysicalQuickSort[MERGE_SORT]
+--------------PhysicalDistribute[DistributionSpecGather]
+----------------PhysicalQuickSort[LOCAL_SORT]
+------------------PhysicalProject
+--------------------PhysicalOlapScan[outer_rf_row_count_right]
+------PhysicalOlapScan[outer_rf_row_count_build(e)]
+
+-- !plain_sort_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((l.k = e.k)) 
otherCondition=() build RFs:RF0 k->k;RF1 k->k
+------PhysicalProject
+--------hashJoin[LEFT_OUTER_JOIN broadcast] hashCondition=((l.k = r.k)) 
otherCondition=()
+----------PhysicalOlapScan[outer_rf_row_count_left(l)] apply RFs: RF0
+----------PhysicalQuickSort[MERGE_SORT]
+------------PhysicalDistribute[DistributionSpecGather]
+--------------PhysicalQuickSort[LOCAL_SORT]
+----------------PhysicalOlapScan[outer_rf_row_count_right] apply RFs: RF1
+------PhysicalOlapScan[outer_rf_row_count_build(e)]
+
+-- !direct_filter_plan --
+PhysicalResultSink
+--PhysicalProject
+----hashJoin[INNER_JOIN broadcast] hashCondition=((r.k = e.k)) 
otherCondition=()
+------PhysicalProject
+--------filter(assert_true((outer_rf_row_count_right.v > 10), 'bad'))
+----------PhysicalOlapScan[outer_rf_row_count_right]
+------PhysicalOlapScan[outer_rf_row_count_build(e)]
+
diff --git 
a/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query40.out 
b/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query40.out
index 5da4034e6f1..12b1e5114cb 100644
--- a/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query40.out
+++ b/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query40.out
@@ -8,7 +8,7 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------hashJoin[INNER_JOIN broadcast] hashCondition=((item.i_item_sk 
= catalog_sales.cs_item_sk)) otherCondition=() build RFs:RF2 
i_item_sk->cs_item_sk
+----------------hashJoin[INNER_JOIN broadcast] hashCondition=((item.i_item_sk 
= catalog_sales.cs_item_sk)) otherCondition=() build RFs:RF2 
i_item_sk->cs_item_sk;RF3 i_item_sk->cr_item_sk
 ------------------PhysicalProject
 --------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF1 d_date_sk->cs_sold_date_sk
 ----------------------PhysicalProject
@@ -18,7 +18,7 @@ PhysicalResultSink
 ------------------------------PhysicalProject
 --------------------------------PhysicalOlapScan[catalog_sales] apply RFs: RF1 
RF2
 ------------------------------PhysicalProject
---------------------------------PhysicalOlapScan[catalog_returns]
+--------------------------------PhysicalOlapScan[catalog_returns] apply RFs: 
RF3
 --------------------------PhysicalProject
 ----------------------------PhysicalOlapScan[warehouse]
 ----------------------PhysicalProject
diff --git 
a/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query75.out 
b/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query75.out
index 77c3a39d350..2a0efd650ab 100644
--- a/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query75.out
+++ b/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query75.out
@@ -9,7 +9,7 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ------------PhysicalUnion
 --------------PhysicalDistribute[DistributionSpecExecutionAny]
 ----------------PhysicalProject
-------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = catalog_sales.cs_item_sk)) otherCondition=() 
build RFs:RF1 i_item_sk->cs_item_sk
+------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = catalog_sales.cs_item_sk)) otherCondition=() 
build RFs:RF1 i_item_sk->cs_item_sk;RF2 i_item_sk->cr_item_sk
 --------------------PhysicalProject
 ----------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = catalog_sales.cs_sold_date_sk)) 
otherCondition=() build RFs:RF0 d_date_sk->cs_sold_date_sk
 ------------------------PhysicalProject
@@ -17,7 +17,7 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ----------------------------PhysicalProject
 ------------------------------PhysicalOlapScan[catalog_sales] apply RFs: RF0 
RF1
 ----------------------------PhysicalProject
-------------------------------PhysicalOlapScan[catalog_returns]
+------------------------------PhysicalOlapScan[catalog_returns] apply RFs: RF2
 ------------------------PhysicalProject
 --------------------------filter(date_dim.d_year IN (1998, 1999))
 ----------------------------PhysicalOlapScan[date_dim]
@@ -26,15 +26,15 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ------------------------PhysicalOlapScan[item]
 --------------PhysicalDistribute[DistributionSpecExecutionAny]
 ----------------PhysicalProject
-------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = store_sales.ss_item_sk)) otherCondition=() 
build RFs:RF3 i_item_sk->ss_item_sk
+------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = store_sales.ss_item_sk)) otherCondition=() 
build RFs:RF4 i_item_sk->ss_item_sk;RF5 i_item_sk->sr_item_sk
 --------------------PhysicalProject
-----------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = store_sales.ss_sold_date_sk)) 
otherCondition=() build RFs:RF2 d_date_sk->ss_sold_date_sk
+----------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = store_sales.ss_sold_date_sk)) 
otherCondition=() build RFs:RF3 d_date_sk->ss_sold_date_sk
 ------------------------PhysicalProject
 --------------------------hashJoin[LEFT_OUTER_JOIN bucketShuffle] 
hashCondition=((store_sales.ss_item_sk = store_returns.sr_item_sk) and 
(store_sales.ss_ticket_number = store_returns.sr_ticket_number)) 
otherCondition=()
 ----------------------------PhysicalProject
-------------------------------PhysicalOlapScan[store_sales] apply RFs: RF2 RF3
+------------------------------PhysicalOlapScan[store_sales] apply RFs: RF3 RF4
 ----------------------------PhysicalProject
-------------------------------PhysicalOlapScan[store_returns]
+------------------------------PhysicalOlapScan[store_returns] apply RFs: RF5
 ------------------------PhysicalProject
 --------------------------filter(date_dim.d_year IN (1998, 1999))
 ----------------------------PhysicalOlapScan[date_dim]
@@ -43,15 +43,15 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ------------------------PhysicalOlapScan[item]
 --------------PhysicalDistribute[DistributionSpecExecutionAny]
 ----------------PhysicalProject
-------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = web_sales.ws_item_sk)) otherCondition=() build 
RFs:RF5 i_item_sk->ws_item_sk
+------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = web_sales.ws_item_sk)) otherCondition=() build 
RFs:RF7 i_item_sk->ws_item_sk;RF8 i_item_sk->wr_item_sk
 --------------------PhysicalProject
-----------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = web_sales.ws_sold_date_sk)) 
otherCondition=() build RFs:RF4 d_date_sk->ws_sold_date_sk
+----------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = web_sales.ws_sold_date_sk)) 
otherCondition=() build RFs:RF6 d_date_sk->ws_sold_date_sk
 ------------------------PhysicalProject
 --------------------------hashJoin[LEFT_OUTER_JOIN bucketShuffle] 
hashCondition=((web_sales.ws_item_sk = web_returns.wr_item_sk) and 
(web_sales.ws_order_number = web_returns.wr_order_number)) otherCondition=()
 ----------------------------PhysicalProject
-------------------------------PhysicalOlapScan[web_sales] apply RFs: RF4 RF5
+------------------------------PhysicalOlapScan[web_sales] apply RFs: RF6 RF7
 ----------------------------PhysicalProject
-------------------------------PhysicalOlapScan[web_returns]
+------------------------------PhysicalOlapScan[web_returns] apply RFs: RF8
 ------------------------PhysicalProject
 --------------------------filter(date_dim.d_year IN (1998, 1999))
 ----------------------------PhysicalOlapScan[date_dim]
@@ -63,9 +63,9 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ------PhysicalDistribute[DistributionSpecGather]
 --------PhysicalTopN[LOCAL_SORT]
 ----------PhysicalProject
-------------hashJoin[INNER_JOIN shuffle] hashCondition=((curr_yr.i_brand_id = 
prev_yr.i_brand_id) and (curr_yr.i_category_id = prev_yr.i_category_id) and 
(curr_yr.i_class_id = prev_yr.i_class_id) and (curr_yr.i_manufact_id = 
prev_yr.i_manufact_id)) otherCondition=(((cast(cast(curr_yr.sales_cnt as 
DECIMALV3(17, 2)) as DECIMALV3(23, 8)) / cast(prev_yr.sales_cnt as 
DECIMALV3(17, 2))) < 0.900000)) build RFs:RF6 i_brand_id->i_brand_id;RF7 
i_class_id->i_class_id;RF8 i_category_id->i_category_i [...]
+------------hashJoin[INNER_JOIN shuffle] hashCondition=((curr_yr.i_brand_id = 
prev_yr.i_brand_id) and (curr_yr.i_category_id = prev_yr.i_category_id) and 
(curr_yr.i_class_id = prev_yr.i_class_id) and (curr_yr.i_manufact_id = 
prev_yr.i_manufact_id)) otherCondition=(((cast(cast(curr_yr.sales_cnt as 
DECIMALV3(17, 2)) as DECIMALV3(23, 8)) / cast(prev_yr.sales_cnt as 
DECIMALV3(17, 2))) < 0.900000)) build RFs:RF9 i_brand_id->i_brand_id;RF10 
i_class_id->i_class_id;RF11 i_category_id->i_category [...]
 --------------filter((curr_yr.d_year = 1999))
-----------------PhysicalCteConsumer ( cteId=CTEId#0 ) apply RFs: RF6 RF7 RF8 
RF9
+----------------PhysicalCteConsumer ( cteId=CTEId#0 ) apply RFs: RF9 RF10 RF11 
RF12
 --------------filter((prev_yr.d_year = 1998))
 ----------------PhysicalCteConsumer ( cteId=CTEId#0 )
 
diff --git 
a/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query80.out 
b/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query80.out
index b767ee99a96..7ec5fe40859 100644
--- a/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query80.out
+++ b/regression-test/data/shape_check/tpcds_sf100/noStatsRfPrune/query80.out
@@ -15,7 +15,7 @@ PhysicalResultSink
 ------------------------PhysicalDistribute[DistributionSpecHash]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((store_sales.ss_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF3 i_item_sk->ss_item_sk
+------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((store_sales.ss_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF3 i_item_sk->ss_item_sk;RF4 i_item_sk->sr_item_sk
 --------------------------------PhysicalProject
 ----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((store_sales.ss_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF2 d_date_sk->ss_sold_date_sk
 ------------------------------------PhysicalProject
@@ -27,7 +27,7 @@ PhysicalResultSink
 ------------------------------------------------PhysicalProject
 
--------------------------------------------------PhysicalOlapScan[store_sales] 
apply RFs: RF1 RF2 RF3
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[store_returns]
+--------------------------------------------------PhysicalOlapScan[store_returns]
 apply RFs: RF4
 --------------------------------------------PhysicalProject
 ----------------------------------------------PhysicalOlapScan[store]
 ----------------------------------------PhysicalProject
@@ -44,19 +44,19 @@ PhysicalResultSink
 ------------------------PhysicalDistribute[DistributionSpecHash]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF7 i_item_sk->cs_item_sk
+------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF8 i_item_sk->cs_item_sk;RF9 i_item_sk->cr_item_sk
 --------------------------------PhysicalProject
-----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF6 d_date_sk->cs_sold_date_sk
+----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF7 d_date_sk->cs_sold_date_sk
 ------------------------------------PhysicalProject
---------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF5 p_promo_sk->cs_promo_sk
+--------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF6 p_promo_sk->cs_promo_sk
 ----------------------------------------PhysicalProject
 ------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_catalog_page_sk = 
catalog_page.cp_catalog_page_sk)) otherCondition=()
 --------------------------------------------PhysicalProject
 ----------------------------------------------hashJoin[LEFT_OUTER_JOIN 
bucketShuffle] hashCondition=((catalog_sales.cs_item_sk = 
catalog_returns.cr_item_sk) and (catalog_sales.cs_order_number = 
catalog_returns.cr_order_number)) otherCondition=()
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[catalog_sales]
 apply RFs: RF5 RF6 RF7
+--------------------------------------------------PhysicalOlapScan[catalog_sales]
 apply RFs: RF6 RF7 RF8
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[catalog_returns]
+--------------------------------------------------PhysicalOlapScan[catalog_returns]
 apply RFs: RF9
 --------------------------------------------PhysicalProject
 ----------------------------------------------PhysicalOlapScan[catalog_page]
 ----------------------------------------PhysicalProject
@@ -73,19 +73,19 @@ PhysicalResultSink
 ------------------------PhysicalDistribute[DistributionSpecHash]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_item_sk = item.i_item_sk)) otherCondition=() build 
RFs:RF11 i_item_sk->ws_item_sk
+------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_item_sk = item.i_item_sk)) otherCondition=() build 
RFs:RF13 i_item_sk->ws_item_sk;RF14 i_item_sk->wr_item_sk
 --------------------------------PhysicalProject
-----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF10 d_date_sk->ws_sold_date_sk
+----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF12 d_date_sk->ws_sold_date_sk
 ------------------------------------PhysicalProject
---------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF9 p_promo_sk->ws_promo_sk
+--------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF11 p_promo_sk->ws_promo_sk
 ----------------------------------------PhysicalProject
 ------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_web_site_sk = web_site.web_site_sk)) 
otherCondition=()
 --------------------------------------------PhysicalProject
 ----------------------------------------------hashJoin[LEFT_OUTER_JOIN 
bucketShuffle] hashCondition=((web_sales.ws_item_sk = web_returns.wr_item_sk) 
and (web_sales.ws_order_number = web_returns.wr_order_number)) otherCondition=()
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[web_sales] 
apply RFs: RF9 RF10 RF11
+--------------------------------------------------PhysicalOlapScan[web_sales] 
apply RFs: RF11 RF12 RF13
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[web_returns]
+--------------------------------------------------PhysicalOlapScan[web_returns]
 apply RFs: RF14
 --------------------------------------------PhysicalProject
 ----------------------------------------------PhysicalOlapScan[web_site]
 ----------------------------------------PhysicalProject
diff --git 
a/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query40.out 
b/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query40.out
index 48caa556705..327d005a820 100644
--- a/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query40.out
+++ b/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query40.out
@@ -8,7 +8,7 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------hashJoin[INNER_JOIN broadcast] hashCondition=((item.i_item_sk 
= catalog_sales.cs_item_sk)) otherCondition=() build RFs:RF2 
i_item_sk->cs_item_sk
+----------------hashJoin[INNER_JOIN broadcast] hashCondition=((item.i_item_sk 
= catalog_sales.cs_item_sk)) otherCondition=() build RFs:RF2 
i_item_sk->cs_item_sk;RF3 i_item_sk->cr_item_sk
 ------------------PhysicalProject
 --------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF1 d_date_sk->cs_sold_date_sk
 ----------------------PhysicalProject
@@ -18,7 +18,7 @@ PhysicalResultSink
 ------------------------------PhysicalProject
 --------------------------------PhysicalOlapScan[catalog_sales] apply RFs: RF0 
RF1 RF2
 ------------------------------PhysicalProject
---------------------------------PhysicalOlapScan[catalog_returns]
+--------------------------------PhysicalOlapScan[catalog_returns] apply RFs: 
RF3
 --------------------------PhysicalProject
 ----------------------------PhysicalOlapScan[warehouse]
 ----------------------PhysicalProject
diff --git 
a/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query75.out 
b/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query75.out
index 77c3a39d350..2a0efd650ab 100644
--- a/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query75.out
+++ b/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query75.out
@@ -9,7 +9,7 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ------------PhysicalUnion
 --------------PhysicalDistribute[DistributionSpecExecutionAny]
 ----------------PhysicalProject
-------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = catalog_sales.cs_item_sk)) otherCondition=() 
build RFs:RF1 i_item_sk->cs_item_sk
+------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = catalog_sales.cs_item_sk)) otherCondition=() 
build RFs:RF1 i_item_sk->cs_item_sk;RF2 i_item_sk->cr_item_sk
 --------------------PhysicalProject
 ----------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = catalog_sales.cs_sold_date_sk)) 
otherCondition=() build RFs:RF0 d_date_sk->cs_sold_date_sk
 ------------------------PhysicalProject
@@ -17,7 +17,7 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ----------------------------PhysicalProject
 ------------------------------PhysicalOlapScan[catalog_sales] apply RFs: RF0 
RF1
 ----------------------------PhysicalProject
-------------------------------PhysicalOlapScan[catalog_returns]
+------------------------------PhysicalOlapScan[catalog_returns] apply RFs: RF2
 ------------------------PhysicalProject
 --------------------------filter(date_dim.d_year IN (1998, 1999))
 ----------------------------PhysicalOlapScan[date_dim]
@@ -26,15 +26,15 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ------------------------PhysicalOlapScan[item]
 --------------PhysicalDistribute[DistributionSpecExecutionAny]
 ----------------PhysicalProject
-------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = store_sales.ss_item_sk)) otherCondition=() 
build RFs:RF3 i_item_sk->ss_item_sk
+------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = store_sales.ss_item_sk)) otherCondition=() 
build RFs:RF4 i_item_sk->ss_item_sk;RF5 i_item_sk->sr_item_sk
 --------------------PhysicalProject
-----------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = store_sales.ss_sold_date_sk)) 
otherCondition=() build RFs:RF2 d_date_sk->ss_sold_date_sk
+----------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = store_sales.ss_sold_date_sk)) 
otherCondition=() build RFs:RF3 d_date_sk->ss_sold_date_sk
 ------------------------PhysicalProject
 --------------------------hashJoin[LEFT_OUTER_JOIN bucketShuffle] 
hashCondition=((store_sales.ss_item_sk = store_returns.sr_item_sk) and 
(store_sales.ss_ticket_number = store_returns.sr_ticket_number)) 
otherCondition=()
 ----------------------------PhysicalProject
-------------------------------PhysicalOlapScan[store_sales] apply RFs: RF2 RF3
+------------------------------PhysicalOlapScan[store_sales] apply RFs: RF3 RF4
 ----------------------------PhysicalProject
-------------------------------PhysicalOlapScan[store_returns]
+------------------------------PhysicalOlapScan[store_returns] apply RFs: RF5
 ------------------------PhysicalProject
 --------------------------filter(date_dim.d_year IN (1998, 1999))
 ----------------------------PhysicalOlapScan[date_dim]
@@ -43,15 +43,15 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ------------------------PhysicalOlapScan[item]
 --------------PhysicalDistribute[DistributionSpecExecutionAny]
 ----------------PhysicalProject
-------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = web_sales.ws_item_sk)) otherCondition=() build 
RFs:RF5 i_item_sk->ws_item_sk
+------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = web_sales.ws_item_sk)) otherCondition=() build 
RFs:RF7 i_item_sk->ws_item_sk;RF8 i_item_sk->wr_item_sk
 --------------------PhysicalProject
-----------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = web_sales.ws_sold_date_sk)) 
otherCondition=() build RFs:RF4 d_date_sk->ws_sold_date_sk
+----------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = web_sales.ws_sold_date_sk)) 
otherCondition=() build RFs:RF6 d_date_sk->ws_sold_date_sk
 ------------------------PhysicalProject
 --------------------------hashJoin[LEFT_OUTER_JOIN bucketShuffle] 
hashCondition=((web_sales.ws_item_sk = web_returns.wr_item_sk) and 
(web_sales.ws_order_number = web_returns.wr_order_number)) otherCondition=()
 ----------------------------PhysicalProject
-------------------------------PhysicalOlapScan[web_sales] apply RFs: RF4 RF5
+------------------------------PhysicalOlapScan[web_sales] apply RFs: RF6 RF7
 ----------------------------PhysicalProject
-------------------------------PhysicalOlapScan[web_returns]
+------------------------------PhysicalOlapScan[web_returns] apply RFs: RF8
 ------------------------PhysicalProject
 --------------------------filter(date_dim.d_year IN (1998, 1999))
 ----------------------------PhysicalOlapScan[date_dim]
@@ -63,9 +63,9 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ------PhysicalDistribute[DistributionSpecGather]
 --------PhysicalTopN[LOCAL_SORT]
 ----------PhysicalProject
-------------hashJoin[INNER_JOIN shuffle] hashCondition=((curr_yr.i_brand_id = 
prev_yr.i_brand_id) and (curr_yr.i_category_id = prev_yr.i_category_id) and 
(curr_yr.i_class_id = prev_yr.i_class_id) and (curr_yr.i_manufact_id = 
prev_yr.i_manufact_id)) otherCondition=(((cast(cast(curr_yr.sales_cnt as 
DECIMALV3(17, 2)) as DECIMALV3(23, 8)) / cast(prev_yr.sales_cnt as 
DECIMALV3(17, 2))) < 0.900000)) build RFs:RF6 i_brand_id->i_brand_id;RF7 
i_class_id->i_class_id;RF8 i_category_id->i_category_i [...]
+------------hashJoin[INNER_JOIN shuffle] hashCondition=((curr_yr.i_brand_id = 
prev_yr.i_brand_id) and (curr_yr.i_category_id = prev_yr.i_category_id) and 
(curr_yr.i_class_id = prev_yr.i_class_id) and (curr_yr.i_manufact_id = 
prev_yr.i_manufact_id)) otherCondition=(((cast(cast(curr_yr.sales_cnt as 
DECIMALV3(17, 2)) as DECIMALV3(23, 8)) / cast(prev_yr.sales_cnt as 
DECIMALV3(17, 2))) < 0.900000)) build RFs:RF9 i_brand_id->i_brand_id;RF10 
i_class_id->i_class_id;RF11 i_category_id->i_category [...]
 --------------filter((curr_yr.d_year = 1999))
-----------------PhysicalCteConsumer ( cteId=CTEId#0 ) apply RFs: RF6 RF7 RF8 
RF9
+----------------PhysicalCteConsumer ( cteId=CTEId#0 ) apply RFs: RF9 RF10 RF11 
RF12
 --------------filter((prev_yr.d_year = 1998))
 ----------------PhysicalCteConsumer ( cteId=CTEId#0 )
 
diff --git 
a/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query80.out 
b/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query80.out
index 5748fd987b6..0d166b2b0ec 100644
--- a/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query80.out
+++ b/regression-test/data/shape_check/tpcds_sf100/no_stats_shape/query80.out
@@ -15,7 +15,7 @@ PhysicalResultSink
 ------------------------PhysicalDistribute[DistributionSpecHash]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((store_sales.ss_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF3 i_item_sk->ss_item_sk
+------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((store_sales.ss_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF3 i_item_sk->ss_item_sk;RF4 i_item_sk->sr_item_sk
 --------------------------------PhysicalProject
 ----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((store_sales.ss_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF2 d_date_sk->ss_sold_date_sk
 ------------------------------------PhysicalProject
@@ -27,7 +27,7 @@ PhysicalResultSink
 ------------------------------------------------PhysicalProject
 
--------------------------------------------------PhysicalOlapScan[store_sales] 
apply RFs: RF0 RF1 RF2 RF3
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[store_returns]
+--------------------------------------------------PhysicalOlapScan[store_returns]
 apply RFs: RF4
 --------------------------------------------PhysicalProject
 ----------------------------------------------PhysicalOlapScan[store]
 ----------------------------------------PhysicalProject
@@ -44,19 +44,19 @@ PhysicalResultSink
 ------------------------PhysicalDistribute[DistributionSpecHash]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF7 i_item_sk->cs_item_sk
+------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF8 i_item_sk->cs_item_sk;RF9 i_item_sk->cr_item_sk
 --------------------------------PhysicalProject
-----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF6 d_date_sk->cs_sold_date_sk
+----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF7 d_date_sk->cs_sold_date_sk
 ------------------------------------PhysicalProject
---------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF5 p_promo_sk->cs_promo_sk
+--------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF6 p_promo_sk->cs_promo_sk
 ----------------------------------------PhysicalProject
-------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_catalog_page_sk = 
catalog_page.cp_catalog_page_sk)) otherCondition=() build RFs:RF4 
cp_catalog_page_sk->cs_catalog_page_sk
+------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_catalog_page_sk = 
catalog_page.cp_catalog_page_sk)) otherCondition=() build RFs:RF5 
cp_catalog_page_sk->cs_catalog_page_sk
 --------------------------------------------PhysicalProject
 ----------------------------------------------hashJoin[LEFT_OUTER_JOIN 
bucketShuffle] hashCondition=((catalog_sales.cs_item_sk = 
catalog_returns.cr_item_sk) and (catalog_sales.cs_order_number = 
catalog_returns.cr_order_number)) otherCondition=()
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[catalog_sales]
 apply RFs: RF4 RF5 RF6 RF7
+--------------------------------------------------PhysicalOlapScan[catalog_sales]
 apply RFs: RF5 RF6 RF7 RF8
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[catalog_returns]
+--------------------------------------------------PhysicalOlapScan[catalog_returns]
 apply RFs: RF9
 --------------------------------------------PhysicalProject
 ----------------------------------------------PhysicalOlapScan[catalog_page]
 ----------------------------------------PhysicalProject
@@ -73,19 +73,19 @@ PhysicalResultSink
 ------------------------PhysicalDistribute[DistributionSpecHash]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_item_sk = item.i_item_sk)) otherCondition=() build 
RFs:RF11 i_item_sk->ws_item_sk
+------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_item_sk = item.i_item_sk)) otherCondition=() build 
RFs:RF13 i_item_sk->ws_item_sk;RF14 i_item_sk->wr_item_sk
 --------------------------------PhysicalProject
-----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF10 d_date_sk->ws_sold_date_sk
+----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF12 d_date_sk->ws_sold_date_sk
 ------------------------------------PhysicalProject
---------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF9 p_promo_sk->ws_promo_sk
+--------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF11 p_promo_sk->ws_promo_sk
 ----------------------------------------PhysicalProject
-------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_web_site_sk = web_site.web_site_sk)) 
otherCondition=() build RFs:RF8 web_site_sk->ws_web_site_sk
+------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_web_site_sk = web_site.web_site_sk)) 
otherCondition=() build RFs:RF10 web_site_sk->ws_web_site_sk
 --------------------------------------------PhysicalProject
 ----------------------------------------------hashJoin[LEFT_OUTER_JOIN 
bucketShuffle] hashCondition=((web_sales.ws_item_sk = web_returns.wr_item_sk) 
and (web_sales.ws_order_number = web_returns.wr_order_number)) otherCondition=()
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[web_sales] 
apply RFs: RF8 RF9 RF10 RF11
+--------------------------------------------------PhysicalOlapScan[web_sales] 
apply RFs: RF10 RF11 RF12 RF13
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[web_returns]
+--------------------------------------------------PhysicalOlapScan[web_returns]
 apply RFs: RF14
 --------------------------------------------PhysicalProject
 ----------------------------------------------PhysicalOlapScan[web_site]
 ----------------------------------------PhysicalProject
diff --git a/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query40.out 
b/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query40.out
index a71d0fb7ab4..e639522ca22 100644
--- a/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query40.out
+++ b/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query40.out
@@ -8,7 +8,7 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------hashJoin[INNER_JOIN broadcast] hashCondition=((item.i_item_sk 
= catalog_sales.cs_item_sk)) otherCondition=() build RFs:RF2 
i_item_sk->cs_item_sk
+----------------hashJoin[INNER_JOIN broadcast] hashCondition=((item.i_item_sk 
= catalog_sales.cs_item_sk)) otherCondition=() build RFs:RF2 
i_item_sk->cs_item_sk;RF3 i_item_sk->cr_item_sk
 ------------------PhysicalProject
 --------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF1 d_date_sk->cs_sold_date_sk
 ----------------------PhysicalProject
@@ -18,7 +18,7 @@ PhysicalResultSink
 ------------------------------PhysicalProject
 --------------------------------PhysicalOlapScan[catalog_sales] apply RFs: RF0 
RF1 RF2
 ------------------------------PhysicalProject
---------------------------------PhysicalOlapScan[catalog_returns]
+--------------------------------PhysicalOlapScan[catalog_returns] apply RFs: 
RF3
 --------------------------PhysicalProject
 ----------------------------PhysicalOlapScan[warehouse]
 ----------------------PhysicalProject
diff --git a/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query72.out 
b/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query72.out
index e9eee9c556c..84328258ea9 100644
--- a/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query72.out
+++ b/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query72.out
@@ -8,28 +8,28 @@ PhysicalResultSink
 ----------PhysicalDistribute[DistributionSpecHash]
 ------------hashAgg[LOCAL]
 --------------PhysicalProject
-----------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_bill_cdemo_sk = 
customer_demographics.cd_demo_sk)) otherCondition=() build RFs:RF9 
cd_demo_sk->cs_bill_cdemo_sk
+----------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_bill_cdemo_sk = 
customer_demographics.cd_demo_sk)) otherCondition=() build RFs:RF11 
cd_demo_sk->cs_bill_cdemo_sk
 ------------------PhysicalProject
---------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_bill_hdemo_sk = 
household_demographics.hd_demo_sk)) otherCondition=() build RFs:RF8 
hd_demo_sk->cs_bill_hdemo_sk
+--------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_bill_hdemo_sk = 
household_demographics.hd_demo_sk)) otherCondition=() build RFs:RF10 
hd_demo_sk->cs_bill_hdemo_sk
 ----------------------PhysicalProject
 ------------------------hashJoin[LEFT_OUTER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_promo_sk = promotion.p_promo_sk)) 
otherCondition=()
 --------------------------PhysicalProject
-----------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = catalog_sales.cs_item_sk)) otherCondition=() 
build RFs:RF6 i_item_sk->cs_item_sk;RF7 i_item_sk->inv_item_sk
+----------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = catalog_sales.cs_item_sk)) otherCondition=() 
build RFs:RF7 i_item_sk->cs_item_sk;RF8 i_item_sk->cr_item_sk;RF9 
i_item_sk->inv_item_sk
 ------------------------------PhysicalProject
---------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_ship_date_sk = d3.d_date_sk)) 
otherCondition=((cast(d3.d_date as DATETIMEV2(0)) > cast((cast(d1.d_date as 
BIGINT) + 5) as DATETIMEV2(0)))) build RFs:RF5 d_date_sk->cs_ship_date_sk
+--------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_ship_date_sk = d3.d_date_sk)) 
otherCondition=((cast(d3.d_date as DATETIMEV2(0)) > cast((cast(d1.d_date as 
BIGINT) + 5) as DATETIMEV2(0)))) build RFs:RF6 d_date_sk->cs_ship_date_sk
 ----------------------------------PhysicalProject
-------------------------------------hashJoin[INNER_JOIN shuffle] 
hashCondition=((catalog_sales.cs_item_sk = inventory.inv_item_sk) and 
(catalog_sales.cs_sold_date_sk = d1.d_date_sk)) 
otherCondition=((inventory.inv_quantity_on_hand < catalog_sales.cs_quantity)) 
build RFs:RF3 d_date_sk->cs_sold_date_sk;RF4 inv_item_sk->cs_item_sk
+------------------------------------hashJoin[INNER_JOIN shuffle] 
hashCondition=((catalog_sales.cs_item_sk = inventory.inv_item_sk) and 
(catalog_sales.cs_sold_date_sk = d1.d_date_sk)) 
otherCondition=((inventory.inv_quantity_on_hand < catalog_sales.cs_quantity)) 
build RFs:RF3 d_date_sk->cs_sold_date_sk;RF4 inv_item_sk->cs_item_sk;RF5 
inv_item_sk->cr_item_sk
 --------------------------------------PhysicalProject
 ----------------------------------------hashJoin[LEFT_OUTER_JOIN shuffle] 
hashCondition=((catalog_returns.cr_item_sk = catalog_sales.cs_item_sk) and 
(catalog_returns.cr_order_number = catalog_sales.cs_order_number)) 
otherCondition=()
 ------------------------------------------PhysicalProject
---------------------------------------------PhysicalOlapScan[catalog_sales] 
apply RFs: RF3 RF4 RF5 RF6 RF8 RF9
+--------------------------------------------PhysicalOlapScan[catalog_sales] 
apply RFs: RF3 RF4 RF6 RF7 RF10 RF11
 ------------------------------------------PhysicalProject
---------------------------------------------PhysicalOlapScan[catalog_returns]
+--------------------------------------------PhysicalOlapScan[catalog_returns] 
apply RFs: RF5 RF8
 --------------------------------------PhysicalProject
 ----------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((warehouse.w_warehouse_sk = inventory.inv_warehouse_sk)) 
otherCondition=() build RFs:RF2 w_warehouse_sk->inv_warehouse_sk
 ------------------------------------------PhysicalProject
 --------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((inventory.inv_date_sk = d2.d_date_sk)) otherCondition=() build 
RFs:RF1 d_date_sk->inv_date_sk
-----------------------------------------------PhysicalOlapScan[inventory] 
apply RFs: RF1 RF2 RF7
+----------------------------------------------PhysicalOlapScan[inventory] 
apply RFs: RF1 RF2 RF9
 ----------------------------------------------PhysicalProject
 ------------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((d1.d_week_seq = d2.d_week_seq)) otherCondition=() build RFs:RF0 
d_week_seq->d_week_seq
 --------------------------------------------------PhysicalProject
diff --git a/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query75.out 
b/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query75.out
index 2771830ea93..147a7ece82b 100644
--- a/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query75.out
+++ b/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query75.out
@@ -8,15 +8,15 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ----------hashAgg[LOCAL]
 ------------PhysicalUnion
 --------------PhysicalProject
-----------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = catalog_sales.cs_sold_date_sk)) 
otherCondition=() build RFs:RF1 d_date_sk->cs_sold_date_sk
+----------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = catalog_sales.cs_sold_date_sk)) 
otherCondition=() build RFs:RF2 d_date_sk->cs_sold_date_sk
 ------------------PhysicalProject
---------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = catalog_sales.cs_item_sk)) otherCondition=() 
build RFs:RF0 i_item_sk->cs_item_sk
+--------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((item.i_item_sk = catalog_sales.cs_item_sk)) otherCondition=() 
build RFs:RF0 i_item_sk->cs_item_sk;RF1 i_item_sk->cr_item_sk
 ----------------------PhysicalProject
 ------------------------hashJoin[LEFT_OUTER_JOIN shuffle] 
hashCondition=((catalog_sales.cs_item_sk = catalog_returns.cr_item_sk) and 
(catalog_sales.cs_order_number = catalog_returns.cr_order_number)) 
otherCondition=()
 --------------------------PhysicalProject
-----------------------------PhysicalOlapScan[catalog_sales] apply RFs: RF0 RF1
+----------------------------PhysicalOlapScan[catalog_sales] apply RFs: RF0 RF2
 --------------------------PhysicalProject
-----------------------------PhysicalOlapScan[catalog_returns]
+----------------------------PhysicalOlapScan[catalog_returns] apply RFs: RF1
 ----------------------PhysicalProject
 ------------------------filter((item.i_category = 'Sports'))
 --------------------------PhysicalOlapScan[item]
@@ -24,15 +24,15 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 --------------------filter(date_dim.d_year IN (2000, 2001))
 ----------------------PhysicalOlapScan[date_dim]
 --------------PhysicalProject
-----------------hashJoin[INNER_JOIN broadcast] hashCondition=((item.i_item_sk 
= store_sales.ss_item_sk)) otherCondition=() build RFs:RF3 i_item_sk->ss_item_sk
+----------------hashJoin[INNER_JOIN broadcast] hashCondition=((item.i_item_sk 
= store_sales.ss_item_sk)) otherCondition=() build RFs:RF4 
i_item_sk->ss_item_sk;RF5 i_item_sk->sr_item_sk
 ------------------PhysicalProject
---------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = store_sales.ss_sold_date_sk)) 
otherCondition=() build RFs:RF2 d_date_sk->ss_sold_date_sk
+--------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = store_sales.ss_sold_date_sk)) 
otherCondition=() build RFs:RF3 d_date_sk->ss_sold_date_sk
 ----------------------PhysicalProject
 ------------------------hashJoin[LEFT_OUTER_JOIN shuffle] 
hashCondition=((store_sales.ss_item_sk = store_returns.sr_item_sk) and 
(store_sales.ss_ticket_number = store_returns.sr_ticket_number)) 
otherCondition=()
 --------------------------PhysicalProject
-----------------------------PhysicalOlapScan[store_sales] apply RFs: RF2 RF3
+----------------------------PhysicalOlapScan[store_sales] apply RFs: RF3 RF4
 --------------------------PhysicalProject
-----------------------------PhysicalOlapScan[store_returns]
+----------------------------PhysicalOlapScan[store_returns] apply RFs: RF5
 ----------------------PhysicalProject
 ------------------------filter(date_dim.d_year IN (2000, 2001))
 --------------------------PhysicalOlapScan[date_dim]
@@ -40,15 +40,15 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 --------------------filter((item.i_category = 'Sports'))
 ----------------------PhysicalOlapScan[item]
 --------------PhysicalProject
-----------------hashJoin[INNER_JOIN broadcast] hashCondition=((item.i_item_sk 
= web_sales.ws_item_sk)) otherCondition=() build RFs:RF5 i_item_sk->ws_item_sk
+----------------hashJoin[INNER_JOIN broadcast] hashCondition=((item.i_item_sk 
= web_sales.ws_item_sk)) otherCondition=() build RFs:RF7 
i_item_sk->ws_item_sk;RF8 i_item_sk->wr_item_sk
 ------------------PhysicalProject
---------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = web_sales.ws_sold_date_sk)) 
otherCondition=() build RFs:RF4 d_date_sk->ws_sold_date_sk
+--------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((date_dim.d_date_sk = web_sales.ws_sold_date_sk)) 
otherCondition=() build RFs:RF6 d_date_sk->ws_sold_date_sk
 ----------------------PhysicalProject
 ------------------------hashJoin[LEFT_OUTER_JOIN shuffle] 
hashCondition=((web_sales.ws_item_sk = web_returns.wr_item_sk) and 
(web_sales.ws_order_number = web_returns.wr_order_number)) otherCondition=()
 --------------------------PhysicalProject
-----------------------------PhysicalOlapScan[web_sales] apply RFs: RF4 RF5
+----------------------------PhysicalOlapScan[web_sales] apply RFs: RF6 RF7
 --------------------------PhysicalProject
-----------------------------PhysicalOlapScan[web_returns]
+----------------------------PhysicalOlapScan[web_returns] apply RFs: RF8
 ----------------------PhysicalProject
 ------------------------filter(date_dim.d_year IN (2000, 2001))
 --------------------------PhysicalOlapScan[date_dim]
@@ -60,9 +60,9 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
 ------PhysicalDistribute[DistributionSpecGather]
 --------PhysicalTopN[LOCAL_SORT]
 ----------PhysicalProject
-------------hashJoin[INNER_JOIN shuffle] hashCondition=((curr_yr.i_brand_id = 
prev_yr.i_brand_id) and (curr_yr.i_category_id = prev_yr.i_category_id) and 
(curr_yr.i_class_id = prev_yr.i_class_id) and (curr_yr.i_manufact_id = 
prev_yr.i_manufact_id)) otherCondition=(((cast(cast(curr_yr.sales_cnt as 
DECIMALV3(17, 2)) as DECIMALV3(23, 8)) / cast(prev_yr.sales_cnt as 
DECIMALV3(17, 2))) < 0.900000)) build RFs:RF6 i_brand_id->i_brand_id;RF7 
i_class_id->i_class_id;RF8 i_category_id->i_category_i [...]
+------------hashJoin[INNER_JOIN shuffle] hashCondition=((curr_yr.i_brand_id = 
prev_yr.i_brand_id) and (curr_yr.i_category_id = prev_yr.i_category_id) and 
(curr_yr.i_class_id = prev_yr.i_class_id) and (curr_yr.i_manufact_id = 
prev_yr.i_manufact_id)) otherCondition=(((cast(cast(curr_yr.sales_cnt as 
DECIMALV3(17, 2)) as DECIMALV3(23, 8)) / cast(prev_yr.sales_cnt as 
DECIMALV3(17, 2))) < 0.900000)) build RFs:RF9 i_brand_id->i_brand_id;RF10 
i_class_id->i_class_id;RF11 i_category_id->i_category [...]
 --------------filter((curr_yr.d_year = 2001))
-----------------PhysicalCteConsumer ( cteId=CTEId#0 ) apply RFs: RF6 RF7 RF8 
RF9
+----------------PhysicalCteConsumer ( cteId=CTEId#0 ) apply RFs: RF9 RF10 RF11 
RF12
 --------------filter((prev_yr.d_year = 2000))
 ----------------PhysicalCteConsumer ( cteId=CTEId#0 )
 
diff --git a/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query80.out 
b/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query80.out
index 06639946abc..a1529b137af 100644
--- a/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query80.out
+++ b/regression-test/data/shape_check/tpcds_sf10t_orc/shape/query80.out
@@ -15,7 +15,7 @@ PhysicalResultSink
 ------------------------PhysicalDistribute[DistributionSpecHash]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((store_sales.ss_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF3 i_item_sk->ss_item_sk
+------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((store_sales.ss_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF3 i_item_sk->ss_item_sk;RF4 i_item_sk->sr_item_sk
 --------------------------------PhysicalProject
 ----------------------------------hashJoin[LEFT_OUTER_JOIN shuffle] 
hashCondition=((store_sales.ss_item_sk = store_returns.sr_item_sk) and 
(store_sales.ss_ticket_number = store_returns.sr_ticket_number)) 
otherCondition=()
 ------------------------------------PhysicalProject
@@ -35,7 +35,7 @@ PhysicalResultSink
 ------------------------------------------filter((date_dim.d_date <= 
'2002-09-05') and (date_dim.d_date >= '2002-08-06'))
 --------------------------------------------PhysicalOlapScan[date_dim]
 ------------------------------------PhysicalProject
---------------------------------------PhysicalOlapScan[store_returns]
+--------------------------------------PhysicalOlapScan[store_returns] apply 
RFs: RF4
 --------------------------------PhysicalProject
 ----------------------------------filter((item.i_current_price > 50.00))
 ------------------------------------PhysicalOlapScan[item]
@@ -44,19 +44,19 @@ PhysicalResultSink
 ------------------------PhysicalDistribute[DistributionSpecHash]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF7 i_item_sk->cs_item_sk
+------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_item_sk = item.i_item_sk)) otherCondition=() 
build RFs:RF8 i_item_sk->cs_item_sk;RF9 i_item_sk->cr_item_sk
 --------------------------------PhysicalProject
-----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF6 d_date_sk->cs_sold_date_sk
+----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF7 d_date_sk->cs_sold_date_sk
 ------------------------------------PhysicalProject
---------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_catalog_page_sk = 
catalog_page.cp_catalog_page_sk)) otherCondition=() build RFs:RF5 
cp_catalog_page_sk->cs_catalog_page_sk
+--------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_catalog_page_sk = 
catalog_page.cp_catalog_page_sk)) otherCondition=() build RFs:RF6 
cp_catalog_page_sk->cs_catalog_page_sk
 ----------------------------------------PhysicalProject
-------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF4 p_promo_sk->cs_promo_sk
+------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((catalog_sales.cs_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF5 p_promo_sk->cs_promo_sk
 --------------------------------------------PhysicalProject
 ----------------------------------------------hashJoin[LEFT_OUTER_JOIN 
shuffle] hashCondition=((catalog_sales.cs_item_sk = catalog_returns.cr_item_sk) 
and (catalog_sales.cs_order_number = catalog_returns.cr_order_number)) 
otherCondition=()
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[catalog_sales]
 apply RFs: RF4 RF5 RF6 RF7
+--------------------------------------------------PhysicalOlapScan[catalog_sales]
 apply RFs: RF5 RF6 RF7 RF8
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[catalog_returns]
+--------------------------------------------------PhysicalOlapScan[catalog_returns]
 apply RFs: RF9
 --------------------------------------------PhysicalProject
 ----------------------------------------------filter((promotion.p_channel_tv = 
'N'))
 ------------------------------------------------PhysicalOlapScan[promotion]
@@ -73,21 +73,21 @@ PhysicalResultSink
 ------------------------PhysicalDistribute[DistributionSpecHash]
 --------------------------hashAgg[LOCAL]
 ----------------------------PhysicalProject
-------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_item_sk = item.i_item_sk)) otherCondition=() build 
RFs:RF11 i_item_sk->ws_item_sk
+------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_item_sk = item.i_item_sk)) otherCondition=() build 
RFs:RF13 i_item_sk->ws_item_sk;RF14 i_item_sk->wr_item_sk
 --------------------------------PhysicalProject
-----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF10 d_date_sk->ws_sold_date_sk
+----------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_sold_date_sk = date_dim.d_date_sk)) 
otherCondition=() build RFs:RF12 d_date_sk->ws_sold_date_sk
 ------------------------------------PhysicalProject
---------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF9 p_promo_sk->ws_promo_sk
+--------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_promo_sk = promotion.p_promo_sk)) 
otherCondition=() build RFs:RF11 p_promo_sk->ws_promo_sk
 ----------------------------------------PhysicalProject
 ------------------------------------------hashJoin[LEFT_OUTER_JOIN shuffle] 
hashCondition=((web_sales.ws_item_sk = web_returns.wr_item_sk) and 
(web_sales.ws_order_number = web_returns.wr_order_number)) otherCondition=()
 --------------------------------------------PhysicalProject
-----------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_web_site_sk = web_site.web_site_sk)) 
otherCondition=() build RFs:RF8 web_site_sk->ws_web_site_sk
+----------------------------------------------hashJoin[INNER_JOIN broadcast] 
hashCondition=((web_sales.ws_web_site_sk = web_site.web_site_sk)) 
otherCondition=() build RFs:RF10 web_site_sk->ws_web_site_sk
 ------------------------------------------------PhysicalProject
---------------------------------------------------PhysicalOlapScan[web_sales] 
apply RFs: RF8 RF9 RF10 RF11
+--------------------------------------------------PhysicalOlapScan[web_sales] 
apply RFs: RF10 RF11 RF12 RF13
 ------------------------------------------------PhysicalProject
 --------------------------------------------------PhysicalOlapScan[web_site]
 --------------------------------------------PhysicalProject
-----------------------------------------------PhysicalOlapScan[web_returns]
+----------------------------------------------PhysicalOlapScan[web_returns] 
apply RFs: RF14
 ----------------------------------------PhysicalProject
 ------------------------------------------filter((promotion.p_channel_tv = 
'N'))
 --------------------------------------------PhysicalOlapScan[promotion]
diff --git 
a/regression-test/suites/query_p0/runtime_filter/outer_join_runtime_filter.groovy
 
b/regression-test/suites/query_p0/runtime_filter/outer_join_runtime_filter.groovy
new file mode 100644
index 00000000000..f75a399061f
--- /dev/null
+++ 
b/regression-test/suites/query_p0/runtime_filter/outer_join_runtime_filter.groovy
@@ -0,0 +1,105 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("outer_join_runtime_filter") {
+    sql "drop table if exists outer_rf_contact"
+    sql "drop table if exists outer_rf_address"
+    sql "drop table if exists outer_rf_phone"
+    sql "drop table if exists outer_rf_event"
+
+    sql """create table outer_rf_contact (org int, k int, v int)
+        duplicate key(org, k) distributed by hash(org) buckets 2
+        properties("replication_num" = "1")"""
+    sql """create table outer_rf_address (org int, k int, v int)
+        duplicate key(org, k) distributed by hash(org) buckets 2
+        properties("replication_num" = "1")"""
+    sql """create table outer_rf_phone (org int, k int, v int)
+        duplicate key(org, k) distributed by hash(org) buckets 2
+        properties("replication_num" = "1")"""
+    sql """create table outer_rf_event (org int, k int)
+        duplicate key(org, k) distributed by hash(org) buckets 2
+        properties("replication_num" = "1")"""
+
+    sql """insert into outer_rf_contact values
+        (1, 1, 11), (1, 1, 111), (1, 2, 12), (2, 1, 21), (2, 2, 22),
+        (1, null, 10), (null, 1, 1), (3, 3, 33)"""
+    sql """insert into outer_rf_address values
+        (1, 1, 100), (1, 1, 101), (2, 2, 202),
+        (1, null, 110), (null, 1, 10), (4, 4, 404)"""
+    sql "insert into outer_rf_phone values (1, 1, 1000), (2, 2, 2000), (3, 3, 
3000)"
+    sql "insert into outer_rf_event values (1, 1), (2, 2), (3, 3), (1, null), 
(null, 1), (1, 0)"
+    sql "sync"
+
+    sql "set disable_join_reorder = true"
+    sql "set enable_runtime_filter_prune = false"
+    sql "set runtime_filter_mode = 'GLOBAL'"
+    sql "set runtime_filter_type = 8"
+    // Waiting for the new consumers also exercises the build-side RF 
dependency.
+    sql "set runtime_filter_wait_infinitely = true"
+
+    def queries = [
+        left: """select a.org, a.k, a.v, b.v from outer_rf_contact a
+            left join outer_rf_address b on a.org = b.org and a.k = b.k
+            inner join outer_rf_event e on a.org = e.org and a.k = e.k""",
+        right: """select a.org, a.k, a.v, b.v from outer_rf_address b
+            right join outer_rf_contact a on b.org = a.org and b.k = a.k
+            inner join outer_rf_event e on a.org = e.org and a.k = e.k""",
+        nested: """select a.org, a.k, a.v, b.v, p.v from outer_rf_contact a
+            left join outer_rf_address b on b.org = a.org and b.k = a.k
+            left join outer_rf_phone p on a.org = p.org and a.k = p.k
+            inner join outer_rf_event e on a.org = e.org and a.k = e.k""",
+        alias: """select a.org, a.k, a.v, b.v from outer_rf_contact a
+            left join (select org as o, k as id, v from outer_rf_address) b
+                on a.org = b.o and a.k = b.id
+            inner join outer_rf_event e on a.org = e.org and a.k = e.k""",
+        shared_cte: """with addresses as (select * from outer_rf_address)
+            select a.org, a.k, a.v, b.v, p.v from outer_rf_contact a
+            left join addresses b on a.org = b.org and a.k = b.k
+            left join addresses p on a.org = p.org and a.k = p.k
+            inner join outer_rf_event e on a.org = e.org and a.k = e.k""",
+        null_safe_outer: """select a.org, a.k, a.v, b.v from outer_rf_contact a
+            left join outer_rf_address b on a.org <=> b.org and a.k <=> b.k
+            inner join outer_rf_event e on a.org = e.org and a.k = e.k""",
+        null_safe_parent: """select a.org, a.k, a.v, b.v from outer_rf_contact 
a
+            left join outer_rf_address b on a.org = b.org and a.k = b.k
+            inner join outer_rf_event e on a.org <=> e.org and a.k <=> e.k""",
+        coalesce: """select a.org, a.k, a.v, b.v from outer_rf_contact a
+            left join outer_rf_address b on a.org = b.org and a.k = b.k
+            inner join outer_rf_event e on a.org = e.org and coalesce(b.k, 0) 
= e.k"""
+    ]
+
+    [false, true].each { expand ->
+        sql "set expand_runtime_filter_by_inner_join = ${expand}"
+        queries.each { name, query ->
+            "order_qt_${name}_${expand}"(query)
+        }
+    }
+
+    qt_left_plan "explain shape plan ${queries.left}"
+    qt_nested_plan "explain shape plan ${queries.nested}"
+
+    // Check IN, BLOOM, MIN_MAX and IN_OR_BLOOM through the same multi-target 
path.
+    [1, 2, 4, 8].each { type ->
+        sql "set runtime_filter_type = ${type}"
+        "order_qt_filter_type_${type}"(queries.left)
+    }
+
+    sql "truncate table outer_rf_address"
+    order_qt_empty_non_preserved queries.left
+    sql "truncate table outer_rf_event"
+    order_qt_empty_producer queries.left
+}
diff --git 
a/regression-test/suites/query_p0/runtime_filter/outer_join_runtime_filter_row_count.groovy
 
b/regression-test/suites/query_p0/runtime_filter/outer_join_runtime_filter_row_count.groovy
new file mode 100644
index 00000000000..60a9f931b56
--- /dev/null
+++ 
b/regression-test/suites/query_p0/runtime_filter/outer_join_runtime_filter_row_count.groovy
@@ -0,0 +1,110 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("outer_join_runtime_filter_row_count") {
+    sql "drop table if exists outer_rf_row_count_left"
+    sql "drop table if exists outer_rf_row_count_payload"
+    sql "drop table if exists outer_rf_row_count_right"
+    sql "drop table if exists outer_rf_row_count_build"
+
+    sql """create table outer_rf_row_count_left (k int)
+        duplicate key(k) distributed by hash(k) buckets 1
+        properties("replication_num" = "1")"""
+    sql """create table outer_rf_row_count_payload (v int)
+        duplicate key(v) distributed by hash(v) buckets 1
+        properties("replication_num" = "1")"""
+    sql """create table outer_rf_row_count_right (k int, v int)
+        duplicate key(k) distributed by hash(k) buckets 1
+        properties("replication_num" = "1")"""
+    sql """create table outer_rf_row_count_build (k int)
+        duplicate key(k) distributed by hash(k) buckets 1
+        properties("replication_num" = "1")"""
+
+    sql "insert into outer_rf_row_count_left values (2)"
+    sql "insert into outer_rf_row_count_payload values (20)"
+    sql "insert into outer_rf_row_count_right values (1, 10), (2, 20)"
+    sql "insert into outer_rf_row_count_build values (2)"
+
+    sql "set disable_join_reorder = true"
+    sql "set enable_runtime_filter_prune = false"
+    sql "set expand_runtime_filter_by_inner_join = true"
+    sql "set runtime_filter_mode = 'GLOBAL'"
+    sql "set runtime_filter_type = 1"
+    sql "set runtime_filter_wait_infinitely = true"
+
+    def scalarQuery = """select l.k, d.v from outer_rf_row_count_left l
+        left join outer_rf_row_count_payload d
+            on l.k = (select r.k from outer_rf_row_count_right r)
+        inner join outer_rf_row_count_build e on l.k = e.k"""
+    qt_scalar_plan "explain shape plan ${scalarQuery}"
+
+    // Keep the Sort and Limit separate to exercise the PhysicalLimit visitor.
+    sql "set disable_nereids_rules = 'LIMIT_SORT_TO_TOP_N,ELIMINATE_SORT'"
+    def limitQuery = """select l.k, r.v from outer_rf_row_count_left l
+        left join (select k, v from outer_rf_row_count_right order by k limit 
1) r on l.k = r.k
+        inner join outer_rf_row_count_build e on l.k = e.k"""
+    qt_limit_plan "explain shape plan ${limitQuery}"
+    order_qt_limit_result limitQuery
+    sql "set disable_nereids_rules = default"
+
+    test {
+        sql scalarQuery
+        exception "Expected EQ 1 to be returned by expression"
+    }
+
+    // Every derived input must evaluate the row with k = 1 before the 
ancestor join filters it.
+    sql "insert into outer_rf_row_count_left values (1)"
+    sql "set disable_nereids_rules = 
'ELIMINATE_SORT,ELIMINATE_ORDER_BY_UNDER_SUBQUERY'"
+    def inputs = [
+        project: """select k, assert_true(v > 10, 'bad') as checked from 
outer_rf_row_count_right""",
+        filter: """select k, v as checked from outer_rf_row_count_right where 
assert_true(v > 10, 'bad')""",
+        window: """select k, sum(cast(assert_true(v > 10, 'bad') as int)) over 
(partition by k) as checked
+            from outer_rf_row_count_right""",
+        aggregate: """select k, sum(cast(assert_true(v > 10, 'bad') as int)) 
as checked
+            from outer_rf_row_count_right group by k""",
+        sort: """select k, v as checked from outer_rf_row_count_right order by 
assert_true(v > 10, 'bad')"""
+    ]
+    for (def expand : [false, true]) {
+        sql "set expand_runtime_filter_by_inner_join = ${expand}"
+        inputs.each { name, input ->
+            def query = """select l.k, r.checked from outer_rf_row_count_left l
+                left join (${input}) r on l.k = r.k
+                inner join outer_rf_row_count_build e on l.k = e.k"""
+            if (expand) {
+                "qt_${name}_plan"("explain shape plan ${query}")
+            }
+            test {
+                sql query
+                exception "bad"
+            }
+        }
+    }
+
+    qt_plain_sort_plan """explain shape plan select l.k, r.v from 
outer_rf_row_count_left l
+        left join (select k, v from outer_rf_row_count_right order by v) r on 
l.k = r.k
+        inner join outer_rf_row_count_build e on l.k = e.k"""
+
+    // The same barrier applies when the derived input is the direct probe 
side of the producer.
+    sql "set expand_runtime_filter_by_inner_join = false"
+    def directQuery = """select r.k, r.checked from (${inputs.filter}) r
+        inner join outer_rf_row_count_build e on r.k = e.k"""
+    qt_direct_filter_plan "explain shape plan ${directQuery}"
+    test {
+        sql directQuery
+        exception "bad"
+    }
+}


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

Reply via email to