Github user maryannxue commented on a diff in the pull request: https://github.com/apache/spark/pull/20345#discussion_r198031184 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/joins.scala --- @@ -84,19 +84,50 @@ object ReorderJoin extends Rule[LogicalPlan] with PredicateHelper { } } + // Extract a list of logical plans to be joined for join-order comparisons. + // Since `ExtractFiltersAndInnerJoins` handles left-deep trees only, this function have + // the same strategy to extract the plan list. + private[optimizer] def extractLeftDeepInnerJoins(plan: LogicalPlan) + : Seq[LogicalPlan] = plan match { + case j @ Join(left, right, _: InnerLike, _) => right +: extractLeftDeepInnerJoins(left) + case p @ Project(_, j @ Join(_, _, _: InnerLike, _)) => extractLeftDeepInnerJoins(j) + case _ => Seq(plan) + } + + private def sameJoinOrder(plan1: LogicalPlan, plan2: LogicalPlan): Boolean = { + extractLeftDeepInnerJoins(plan1) == extractLeftDeepInnerJoins(plan2) + } + + private def mayCreateOrderedJoin( + originalPlan: LogicalPlan, + input: Seq[(LogicalPlan, InnerLike)], + conditions: Seq[Expression]): LogicalPlan = { + val orderedJoins = createOrderedJoin(input, conditions) + if (!sameJoinOrder(orderedJoins, originalPlan)) { + if (originalPlan.output != orderedJoins.output) { --- End diff -- I think this also fixes an existing bug for join reordering, right? Shall we add it to the issue description?
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org