morningman commented on code in PR #66435: URL: https://github.com/apache/doris/pull/66435#discussion_r3711364821
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateMarkJoin.java: ########## @@ -0,0 +1,115 @@ +// 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.rules.rewrite; + +import org.apache.doris.nereids.rules.Rule; +import org.apache.doris.nereids.rules.RuleType; +import org.apache.doris.nereids.trees.expressions.Alias; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.MarkJoinSlotReference; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral; +import org.apache.doris.nereids.trees.plans.JoinType; +import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.logical.LogicalFilter; +import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; +import org.apache.doris.nereids.trees.plans.logical.LogicalProject; +import org.apache.doris.nereids.util.ExpressionUtils; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; + +import java.util.List; +import java.util.Optional; +import java.util.Set; + +/** + * Eliminate a mark join whose mark slot is only consumed, as a bare conjunct, by the filter + * directly above it. + * + * A LEFT SEMI mark join outputs every left row together with a three-valued mark slot + * (TRUE / FALSE / NULL) recording whether the semi condition matched. A filter that requires + * the mark slot to be TRUE discards NULL rows exactly like FALSE rows, so the pair degenerates + * to a plain LEFT SEMI JOIN over the same conjuncts: + * <pre> + * filter(m and rest) project(join output, TRUE as m) Review Comment: Good catch — the scenario is real, and the rule already guards it: `markSlotOnlyUsedAsBareConjunct` only fires when the mark slot appears as a **bare top-level conjunct** of the filter, and bails whenever the mark slot occurs inside any compound predicate. For `filter((m and rest) is null)` the mark slot is referenced inside the `is null` expression, so the guard rejects it and the mark join stays as it is. What was genuinely misleading is the javadoc diagram, which showed the rewrite without its precondition. Fixed in 1a97e7f6523: stated the precondition explicitly under the diagram, and added unit tests pinning the behavior for both `(m and x) is null` and `m is null` — the mark join survives the full rewrite pipeline in both. -- 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]
