xzj7019 commented on code in PR #49096: URL: https://github.com/apache/doris/pull/49096#discussion_r2055619180
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/JoinSkewAddSalt.java: ########## @@ -0,0 +1,212 @@ +// 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.hint.DistributeHint; +import org.apache.doris.nereids.pattern.MatchingContext; +import org.apache.doris.nereids.rules.Rule; +import org.apache.doris.nereids.rules.RuleType; +import org.apache.doris.nereids.rules.exploration.join.JoinReorderContext; +import org.apache.doris.nereids.trees.expressions.Alias; +import org.apache.doris.nereids.trees.expressions.CaseWhen; +import org.apache.doris.nereids.trees.expressions.Cast; +import org.apache.doris.nereids.trees.expressions.EqualTo; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.InPredicate; +import org.apache.doris.nereids.trees.expressions.IsNull; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.Slot; +import org.apache.doris.nereids.trees.expressions.SlotReference; +import org.apache.doris.nereids.trees.expressions.WhenClause; +import org.apache.doris.nereids.trees.expressions.functions.Function; +import org.apache.doris.nereids.trees.expressions.functions.generator.ExplodeNumbers; +import org.apache.doris.nereids.trees.expressions.functions.scalar.If; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Random; +import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral; +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.Plan; +import org.apache.doris.nereids.trees.plans.algebra.SetOperation.Qualifier; +import org.apache.doris.nereids.trees.plans.logical.LogicalGenerate; +import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; +import org.apache.doris.nereids.trees.plans.logical.LogicalProject; +import org.apache.doris.nereids.trees.plans.logical.LogicalUnion; +import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.types.IntegerType; +import org.apache.doris.nereids.types.TinyIntType; +import org.apache.doris.nereids.util.TypeCoercionUtils; + +import com.google.common.collect.ImmutableList; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * LogicalJoin(type:inner, t1.a=t2.a, hint:skew(t1.a(1,2))) + * +--LogicalOlapScan(t1) + * +--LogicalOlapScan(t2) + * -> + * LogicalJoin (type:inner, t1.a=t2.a and r1=r2) + * |--LogicalProject (t1.a, CASE WHEN t1.a IS NULL THEN random(0, 999) + * WHEN t1.a IN (1, 2) THEN random(0, 999) ELSE 0 END AS r1)) + * | +--LogicalOlapScan(t1) + * +--LogicalProject (projections: t2.a, if(explodeNumber IS NULL, 0, explodeNumber) as r2) + * +--LogicalJoin (type=right_outer_join, t2.a=skewValue) + * |--LogicalGenerate(generators=[explode_numbers(1000)], generatorOutput=[explodeNumber]) + * | +--LogicalUnion(outputs=[skewValue], constantExprsList(1,2)) + * +--LogicalOlapScan(t2) + * */ +public class JoinSkewAddSalt extends OneRewriteRuleFactory { Review Comment: add detailed explaination in desc part of this pr, seems the hint's usage scenario has preconditions, such as the current join is a shuffle join, otherwise bc can resolve the skew directly, so the right part of this join can't skew at skew values otherwise the explode can be very expensive, and another point is consider the left skew only case, we only need to do the right side non-skew explode and use the right outer join to do the transformation. -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org