BiteTheDDDDt commented on code in PR #64102: URL: https://github.com/apache/doris/pull/64102#discussion_r3360184893
########## regression-test/suites/correctness_p0/test_runtime_filter_outer_join_nullable_side.groovy: ########## @@ -0,0 +1,94 @@ +// 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("test_runtime_filter_outer_join_nullable_side") { + sql "drop table if exists rf_outer_join_nullable_a" + sql "drop table if exists rf_outer_join_nullable_b" + sql "drop table if exists rf_outer_join_nullable_c" + + sql """ + create table rf_outer_join_nullable_a ( + pk int + ) + duplicate key(pk) + distributed by hash(pk) buckets 1 + properties("replication_num" = "1") + """ + + sql """ + create table rf_outer_join_nullable_b ( + pk int + ) + duplicate key(pk) + distributed by hash(pk) buckets 1 + properties("replication_num" = "1") + """ + + sql """ + create table rf_outer_join_nullable_c ( + pk int + ) + duplicate key(pk) + distributed by hash(pk) buckets 1 + properties("replication_num" = "1") + """ + + sql "insert into rf_outer_join_nullable_a values (1)" + sql "insert into rf_outer_join_nullable_b values (1)" + sql "insert into rf_outer_join_nullable_c values (0)" + sql "sync" + + sql "set enable_nereids_planner=true" + sql "set enable_fallback_to_original_planner=false" + sql "set disable_join_reorder=true" + sql "set runtime_filter_mode='GLOBAL'" + sql "set runtime_filter_type='IN_OR_BLOOM_FILTER'" + sql "set runtime_filter_wait_infinitely=true" + sql "set enable_runtime_filter_prune=false" + sql "set parallel_pipeline_task_num=1" + + def query = """ + select coalesce(b.pk, 0) as k, count(*) as cnt + from rf_outer_join_nullable_a a + left join rf_outer_join_nullable_b b on a.pk = b.pk + inner join rf_outer_join_nullable_c c on coalesce(b.pk, 0) = c.pk + group by 1 + order by 1 + """ + + test { Review Comment: 已改:去掉了手写 assert,改成 qt_shape,并新增 regression-test/data/correctness_p0/test_runtime_filter_outer_join_nullable_side.out。shape golden 里没有 build/apply RF;实际结果也改成 qt_result。 ########## fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPushDownVisitor.java: ########## @@ -325,15 +328,53 @@ public Boolean visitPhysicalNestedLoopJoin(PhysicalNestedLoopJoin<? extends Plan boolean pushed = false; Plan left = join.left(); Plan right = join.right(); - if (left.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())) { + if (left.getOutputSet().containsAll(ctx.probeExpr.getInputSlots()) + && canPushThroughJoinChild(join, true, ctx)) { pushed |= left.accept(this, ctx); } - if (right.getOutputSet().containsAll(ctx.probeExpr.getInputSlots())) { + if (right.getOutputSet().containsAll(ctx.probeExpr.getInputSlots()) + && canPushThroughJoinChild(join, false, ctx)) { pushed |= right.accept(this, ctx); } return pushed; } + private boolean canPushThroughJoinChild(AbstractPhysicalJoin<? extends Plan, ? extends Plan> join, + boolean isLeftChild, PushDownContext ctx) { + if (join.equals(ctx.builderNode) || !isNullGeneratingChild(join.getJoinType(), isLeftChild)) { + return true; + } + return isNullPropagating(ctx.probeExpr); Review Comment: 这里保留 isNullPropagating 是为了不把安全的 RF 下推也一起禁掉。比如 b.pk = c.pk 这种 null-propagating probe,outer join 生成的 NULL 在父 join 仍会被拒绝,下推只会提前过滤最终不会匹配的行;但 coalesce(b.pk, 0) = c.pk 会把生成的 NULL 转成 0,可能重新匹配并改变结果。已补代码注释,并新增 testPushDownNullPropagatingRuntimeFilterThroughOuterJoin 覆盖这个正例。 -- 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]
