LukaZdravic commented on code in PR #60403:
URL: https://github.com/apache/spark/pull/60403#discussion_r4564545590
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -2315,6 +2315,24 @@ object InferFiltersFromConstraints extends
Rule[LogicalPlan]
case _ => join
}
+
+ // A right row that fails the ON condition is never the match of any left
row, so a filter
+ // that follows from the left constraints and the ON condition can drop it
before the join.
+ // An inner join also drops the left rows without a match, so its left
side gets one too.
+ case j: AsOfJoin =>
+ // Leave out IN and correlated EXISTS filters. They become joins below
the as-of join. A
+ // sort-merge semi join keeps only the key order, so the as-of join
sorts that input again.
+ // A NOT IN anti join runs over every row of that input, and it is a
nested-loop join when
+ // spark.sql.optimizeNullAwareAntiJoin is off.
+ val allConstraints = getAllConstraints(j.left, j.right, j.condition)
+ .filterNot(SubqueryExpression.hasInOrCorrelatedExistsSubquery)
+ val newLeft = j.joinType match {
+ case Inner => inferNewFilter(j.left, allConstraints)
+ case LeftOuter => j.left
+ case other =>
+ throw SparkException.internalError(s"Unexpected as-of join type:
$other")
+ }
+ j.copy(left = newLeft, right = inferNewFilter(j.right, allConstraints))
Review Comment:
Confirmed, 2 scans and 2 shuffles instead of 1 scan and a reused exchange,
with AQE on and off. I kept the filter, because it drops right rows that can
never match before the shuffle. Thanks!
--
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]