dongjoon-hyun commented on code in PR #60711:
URL: https://github.com/apache/spark/pull/60711#discussion_r4646268722
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/joins.scala:
##########
@@ -97,8 +97,15 @@ object ReorderJoin extends Rule[LogicalPlan] with
PredicateHelper {
def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
_.containsPattern(INNER_LIKE_JOIN), ruleId) {
+ // `ExtractFiltersAndInnerJoins` does not flatten a lower join or filter
with a condition that
+ // may not move (see `splitMovable`), so such conditions are only in the
top join or filter.
+ // They stay in a filter above all the joins, which takes the place of a
top filter. It can not
+ // take the place of a top join, since `CombineFilters` can merge a filter
above it into it,
+ // e.g. one with a subquery that would stay above the join, and `NULL AND
x` evaluates `x`. So
+ // the joins are not reordered when the top join has such a condition.
case p @ ExtractFiltersAndInnerJoins(input, conditions)
- if input.size > 2 && conditions.nonEmpty =>
+ if input.size > 2 && conditions.nonEmpty &&
+ (p.isInstanceOf[Filter] || splitMovable(conditions,
input.map(_._1))._2.isEmpty) =>
Review Comment:
Thank you for checking the `CAST` case. I confirmed this one too: both forms
plan a `BroadcastNestedLoopJoin` with the previous commit and fail with
`spark.sql.crossJoin.enabled=false`, while master, v4.2.1 and v4.3.0 use hash
joins.
I took your suggestion: the refusal is gone, so the filter that keeps the
throwable condition of the top join takes its place again, and `CombineFilters`
passes `afterBarrier = nc.throwable` to `splitMovable`, so a conjunct that can
fail stays in a filter above it. `CombineFilters` already does not combine into
a non-deterministic inner condition, so the filter that `ReorderJoin` keeps is
covered either way. Both forms plan hash joins, your subquery query returns 2,
the `CAST` query returns no rows, and the earlier forms return the same rows as
before. The new `FilterPushdownSuite` test checks that a condition that can
fail stays above a throwable one while one that can not fail is combined.
Besides the suites you ran, `CheckConstraintSuite`, `JDBCV2Suite` and the plan
stability suites pass, with no golden file changes.
--
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]