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


##########
regression-test/conf/regression-conf.groovy:
##########
@@ -24,23 +24,23 @@ defaultDb = "regression_test"
 // init cmd like: select @@session.tx_read_only
 // at each time we connect.
 // add allowLoadLocalInfile so that the jdbc can execute mysql load data from 
client.
-jdbcUrl = 
"jdbc:mysql://127.0.0.1:9030/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"
-targetJdbcUrl = 
"jdbc:mysql://127.0.0.1:9030/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"
+jdbcUrl = 
"jdbc:mysql://127.0.0.1:29031/?useLocalSessionState=true&allowLoadLocalInfile=true&zeroDateTimeBehavior=round"

Review Comment:
   These are local runner/worktree ports from the test environment, not part of 
the feature. `AGENTS.md` explicitly says environment-only changes like `conf/` 
updates must not be committed. Please drop this file from the PR.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterGenerator.java:
##########
@@ -473,65 +462,164 @@ public PhysicalPlan 
visitPhysicalNestedLoopJoin(PhysicalNestedLoopJoin<? extends
     @Override
     public PhysicalPlan visitPhysicalProject(PhysicalProject<? extends Plan> 
project, CascadesContext context) {
         project.child().accept(this, context);
-        RuntimeFilterContext ctx = context.getRuntimeFilterContext();
-        // change key when encounter alias.
-        // TODO: same action will be taken for set operation
-        for (Expression expression : project.getProjects()) {
-            if (expression.children().isEmpty()) {
-                continue;
-            }
-            Expression expr = 
ExpressionUtils.getSingleNumericSlotOrExpressionCoveredByCast(expression.child(0));
-            if (expr instanceof NamedExpression
-                    && ctx.aliasTransferMapContains((NamedExpression) expr)) {
-                if (expression instanceof Alias) {
-                    Alias alias = ((Alias) expression);
-                    ctx.aliasTransferMapPut(alias.toSlot(), 
ctx.getAliasTransferPair((NamedExpression) expr));
-                }
-            }
-        }
         return project;
     }
 
     @Override
     public Plan visitPhysicalOneRowRelation(PhysicalOneRowRelation 
oneRowRelation, CascadesContext context) {
-        // TODO: OneRowRelation will be translated to union. Union node cannot 
apply runtime filter now
-        //  so, just return itself now, until runtime filter could apply on 
any node.
         return oneRowRelation;
     }
 
     @Override
     public PhysicalRelation visitPhysicalRelation(PhysicalRelation relation, 
CascadesContext context) {
-        if (relation instanceof PhysicalSchemaScan) {
-            return relation;
-        }
-        // add all the slots in map.
-        RuntimeFilterContext ctx = context.getRuntimeFilterContext();
-        relation.getOutput().forEach(slot -> ctx.aliasTransferMapPut(slot, 
Pair.of(relation, slot)));
         return relation;
     }
 
     @Override
     public Plan 
visitPhysicalLazyMaterializeOlapScan(PhysicalLazyMaterializeOlapScan scan, 
CascadesContext context) {
-        RuntimeFilterContext ctx = context.getRuntimeFilterContext();
-        scan.getOutput().forEach(slot -> ctx.aliasTransferMapPut(slot, 
Pair.of(scan, slot)));
         return scan;
     }
 
     @Override
     public PhysicalSetOperation visitPhysicalSetOperation(PhysicalSetOperation 
setOperation, CascadesContext context) {
         setOperation.children().forEach(child -> child.accept(this, context));
+        return setOperation;
+    }
+
+    @Override
+    public Plan visitPhysicalIntersect(PhysicalIntersect intersect, 
CascadesContext context) {
+        visitPhysicalSetOperation(intersect, context);
+        generateRuntimeFilterForSetOperation(intersect, context);
+        return intersect;
+    }
+
+    @Override
+    public Plan visitPhysicalExcept(PhysicalExcept except, CascadesContext 
context) {
+        visitPhysicalSetOperation(except, context);
+        generateRuntimeFilterForSetOperation(except, context);
+        return except;
+    }
+
+    private void generateRuntimeFilterForSetOperation(PhysicalSetOperation 
setOp, CascadesContext context) {
+        AbstractPlan child0 = (AbstractPlan) setOp.child(0);
+        if (child0.getStats() == null
+                || ConnectContext.get() == null
+                || ConnectContext.get().getSessionVariable() == null
+                || child0.getStats().getRowCount()
+                    >= 
ConnectContext.get().getSessionVariable().runtimeFilterMaxBuildRowCount) {
+            return;
+        }
         RuntimeFilterContext ctx = context.getRuntimeFilterContext();
-        if (!setOperation.getRegularChildrenOutputs().isEmpty()) {
-            // example: RegularChildrenOutputs is empty
-            // "select 1 a, 2 b union all select 3, 4 union all select 10 e, 
20 f;"
-            for (int i = 0; i < setOperation.getOutput().size(); i++) {
-                Pair childSlotPair = 
ctx.getAliasTransferPair(setOperation.getRegularChildOutput(0).get(i));
-                if (childSlotPair != null) {
-                    ctx.aliasTransferMapPut(setOperation.getOutput().get(i), 
childSlotPair);
+        List<TRuntimeFilterType> legalTypes = 
Arrays.stream(TRuntimeFilterType.values())
+                .filter(type -> 
ctx.getSessionVariable().allowedRuntimeFilterType(type))
+                .filter(type -> type != TRuntimeFilterType.BITMAP)
+                .collect(Collectors.toList());
+
+        boolean hasUnknownColStats = 
context.getStatementContext().isHasUnknownColStats();
+        for (int slotIdx : chooseSourceSlotsForSetOp(setOp)) {
+            Expression sourceExpression = 
setOp.getRegularChildrenOutputs().get(0).get(slotIdx);
+            long buildNdvOrRowCount = computeBuildNdvOrRowCount(child0, 
sourceExpression);
+            for (int childId = 1; childId < setOp.children().size(); 
childId++) {
+                Expression targetExpression = 
setOp.getRegularChildrenOutputs().get(childId).get(slotIdx);
+                pushDownSetOpRuntimeFilter(setOp.child(childId), 
targetExpression,
+                        sourceExpression, setOp, ctx, legalTypes,
+                        buildNdvOrRowCount, slotIdx, hasUnknownColStats);
+            }
+        }
+    }
+
+    /**
+     * Push down runtime filter for set operations (INTERSECT/EXCEPT) by tree 
traversal.
+     * Unlike join RF push-down which uses aliasTransferMap, this method 
rewrites the target
+     * expression through projects and resolves to scans directly.
+     */
+    private boolean pushDownSetOpRuntimeFilter(Plan plan, Expression 
targetExpr,
+            Expression srcExpr, PhysicalSetOperation setOp, 
RuntimeFilterContext ctx,
+            List<TRuntimeFilterType> legalTypes, long buildNdvOrRowCount, int 
exprOrder,
+            boolean hasUnknownColStats) {
+        if (plan instanceof PhysicalRelation) {
+            PhysicalRelation relation = (PhysicalRelation) plan;
+            if (relation instanceof PhysicalSchemaScan) {
+                return false;
+            }
+            if (targetExpr.getInputSlots().size() != 1) {
+                return false;
+            }
+            Slot targetSlot = targetExpr.getInputSlots().iterator().next();
+            if (!relation.getOutputSet().contains(targetSlot)) {
+                return false;
+            }
+            for (TRuntimeFilterType type : legalTypes) {
+                RuntimeFilter filter = 
ctx.getRuntimeFilterBySrcAndType(srcExpr, type, setOp);
+                if (filter != null) {
+                    if (!filter.hasTargetScan(relation)) {
+                        relation.addAppliedRuntimeFilter(filter);
+                        filter.addTargetSlot(targetSlot, targetExpr, relation);
+                        ctx.addJoinToTargetMap(setOp, targetSlot.getExprId());
+                        ctx.setTargetExprIdToFilter(targetSlot.getExprId(), 
filter);
+                        ctx.setTargetsOnScanNode(relation, targetSlot);
+                    }
+                } else {
+                    filter = new 
RuntimeFilter(ctx.getRuntimeFilterIdGen().getNextId(),
+                            srcExpr, ImmutableList.of(targetSlot), 
ImmutableList.of(targetExpr),
+                            type, exprOrder, setOp, false, buildNdvOrRowCount,
+                            !hasUnknownColStats, 
TMinMaxRuntimeFilterType.MIN_MAX, relation);
+                    relation.addAppliedRuntimeFilter(filter);
+                    ctx.addJoinToTargetMap(setOp, targetSlot.getExprId());
+                    ctx.setTargetExprIdToFilter(targetSlot.getExprId(), 
filter);
+                    ctx.setTargetsOnScanNode(relation, targetSlot);
+                    ctx.setRuntimeFilterIdentityToFilter(srcExpr, type, setOp, 
filter);
                 }
             }
+            return true;
         }
-        return setOperation;
+        if (plan instanceof PhysicalProject) {
+            PhysicalProject<?> project = (PhysicalProject<?>) plan;
+            if 
(!project.getOutputSet().containsAll(targetExpr.getInputSlots())) {
+                return false;
+            }
+            Map<Slot, Expression> replaceMap = 
ExpressionUtils.generateReplaceMap(project.getProjects());
+            Expression newTarget = targetExpr.rewriteDownShortCircuit(
+                    e -> replaceMap.getOrDefault(e, e));
+            if (newTarget.getInputSlots().size() == 1) {

Review Comment:
   This fallback recursion changes semantics for set-operation RF pushdown. In 
the deleted V2 visitor, `PhysicalTopN` stopped pushdown entirely and 
`PhysicalWindow`/join nodes had extra guards; here we now recurse through any 
unmatched node whose child still exposes the slot. That means a query like 
`select a from t1 except (select a from t2 order by b limit 10)` can push the 
RF below the `TopN`, filtering rows before the top-10 is chosen and therefore 
changing which rows participate in the EXCEPT. Please keep the 
operator-specific stop conditions instead of using the generic 
recurse-into-children fallback here.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterGenerator.java:
##########
@@ -473,65 +462,164 @@ public PhysicalPlan 
visitPhysicalNestedLoopJoin(PhysicalNestedLoopJoin<? extends
     @Override
     public PhysicalPlan visitPhysicalProject(PhysicalProject<? extends Plan> 
project, CascadesContext context) {
         project.child().accept(this, context);
-        RuntimeFilterContext ctx = context.getRuntimeFilterContext();
-        // change key when encounter alias.
-        // TODO: same action will be taken for set operation
-        for (Expression expression : project.getProjects()) {
-            if (expression.children().isEmpty()) {
-                continue;
-            }
-            Expression expr = 
ExpressionUtils.getSingleNumericSlotOrExpressionCoveredByCast(expression.child(0));
-            if (expr instanceof NamedExpression
-                    && ctx.aliasTransferMapContains((NamedExpression) expr)) {
-                if (expression instanceof Alias) {
-                    Alias alias = ((Alias) expression);
-                    ctx.aliasTransferMapPut(alias.toSlot(), 
ctx.getAliasTransferPair((NamedExpression) expr));
-                }
-            }
-        }
         return project;
     }
 
     @Override
     public Plan visitPhysicalOneRowRelation(PhysicalOneRowRelation 
oneRowRelation, CascadesContext context) {
-        // TODO: OneRowRelation will be translated to union. Union node cannot 
apply runtime filter now
-        //  so, just return itself now, until runtime filter could apply on 
any node.
         return oneRowRelation;
     }
 
     @Override
     public PhysicalRelation visitPhysicalRelation(PhysicalRelation relation, 
CascadesContext context) {
-        if (relation instanceof PhysicalSchemaScan) {
-            return relation;
-        }
-        // add all the slots in map.
-        RuntimeFilterContext ctx = context.getRuntimeFilterContext();
-        relation.getOutput().forEach(slot -> ctx.aliasTransferMapPut(slot, 
Pair.of(relation, slot)));
         return relation;
     }
 
     @Override
     public Plan 
visitPhysicalLazyMaterializeOlapScan(PhysicalLazyMaterializeOlapScan scan, 
CascadesContext context) {
-        RuntimeFilterContext ctx = context.getRuntimeFilterContext();
-        scan.getOutput().forEach(slot -> ctx.aliasTransferMapPut(slot, 
Pair.of(scan, slot)));
         return scan;
     }
 
     @Override
     public PhysicalSetOperation visitPhysicalSetOperation(PhysicalSetOperation 
setOperation, CascadesContext context) {
         setOperation.children().forEach(child -> child.accept(this, context));
+        return setOperation;
+    }
+
+    @Override
+    public Plan visitPhysicalIntersect(PhysicalIntersect intersect, 
CascadesContext context) {
+        visitPhysicalSetOperation(intersect, context);
+        generateRuntimeFilterForSetOperation(intersect, context);
+        return intersect;
+    }
+
+    @Override
+    public Plan visitPhysicalExcept(PhysicalExcept except, CascadesContext 
context) {
+        visitPhysicalSetOperation(except, context);
+        generateRuntimeFilterForSetOperation(except, context);
+        return except;
+    }
+
+    private void generateRuntimeFilterForSetOperation(PhysicalSetOperation 
setOp, CascadesContext context) {
+        AbstractPlan child0 = (AbstractPlan) setOp.child(0);
+        if (child0.getStats() == null
+                || ConnectContext.get() == null
+                || ConnectContext.get().getSessionVariable() == null
+                || child0.getStats().getRowCount()
+                    >= 
ConnectContext.get().getSessionVariable().runtimeFilterMaxBuildRowCount) {
+            return;
+        }
         RuntimeFilterContext ctx = context.getRuntimeFilterContext();
-        if (!setOperation.getRegularChildrenOutputs().isEmpty()) {
-            // example: RegularChildrenOutputs is empty
-            // "select 1 a, 2 b union all select 3, 4 union all select 10 e, 
20 f;"
-            for (int i = 0; i < setOperation.getOutput().size(); i++) {
-                Pair childSlotPair = 
ctx.getAliasTransferPair(setOperation.getRegularChildOutput(0).get(i));
-                if (childSlotPair != null) {
-                    ctx.aliasTransferMapPut(setOperation.getOutput().get(i), 
childSlotPair);
+        List<TRuntimeFilterType> legalTypes = 
Arrays.stream(TRuntimeFilterType.values())
+                .filter(type -> 
ctx.getSessionVariable().allowedRuntimeFilterType(type))
+                .filter(type -> type != TRuntimeFilterType.BITMAP)
+                .collect(Collectors.toList());
+
+        boolean hasUnknownColStats = 
context.getStatementContext().isHasUnknownColStats();
+        for (int slotIdx : chooseSourceSlotsForSetOp(setOp)) {
+            Expression sourceExpression = 
setOp.getRegularChildrenOutputs().get(0).get(slotIdx);
+            long buildNdvOrRowCount = computeBuildNdvOrRowCount(child0, 
sourceExpression);
+            for (int childId = 1; childId < setOp.children().size(); 
childId++) {
+                Expression targetExpression = 
setOp.getRegularChildrenOutputs().get(childId).get(slotIdx);
+                pushDownSetOpRuntimeFilter(setOp.child(childId), 
targetExpression,
+                        sourceExpression, setOp, ctx, legalTypes,
+                        buildNdvOrRowCount, slotIdx, hasUnknownColStats);
+            }
+        }
+    }
+
+    /**
+     * Push down runtime filter for set operations (INTERSECT/EXCEPT) by tree 
traversal.
+     * Unlike join RF push-down which uses aliasTransferMap, this method 
rewrites the target
+     * expression through projects and resolves to scans directly.

Review Comment:
   This branch now accepts every `PhysicalRelation` except 
`PhysicalSchemaScan`, but the old implementations only targeted relations that 
actually support runtime-filter pushdown (`PhysicalCatalogRelation` / 
`PhysicalCTEConsumer`, or `canPushDownRuntimeFilter() == true`). With the new 
code, unsupported targets such as `PhysicalOneRowRelation` or 
`PhysicalEmptyRelation` can be added to the same RF group. Later, 
`RuntimeFilterTranslator.createLegacyRuntimeFilter()` aborts the whole group on 
the first target whose `targetSlotRef` is missing (`hasInvalidTarget = true; 
break;`), so one constant/empty child can silently drop valid sibling targets 
too. A query like `select a from t1 intersect select 1 as a intersect select a 
from t2` now loses the RF on `t2` because the constant child poisons the shared 
filter.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to