maropu commented on a change in pull request #31045:
URL: https://github.com/apache/spark/pull/31045#discussion_r552255103
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -1612,9 +1612,12 @@ object ConvertToLocalRelation extends Rule[LogicalPlan] {
* {{{
* SELECT DISTINCT f1, f2 FROM t ==> SELECT f1, f2 FROM t GROUP BY f1, f2
* }}}
+ *
+ * The [[Distinct]] can be ignored if it is the right child of a left semi or
anti join.
*/
object ReplaceDistinctWithAggregate extends Rule[LogicalPlan] {
- def apply(plan: LogicalPlan): LogicalPlan = plan transform {
+ def apply(plan: LogicalPlan): LogicalPlan = plan transformDown {
+ case j @ Join(_, Distinct(right), LeftSemiOrAnti(_), _, _) => j.copy(right
= right)
Review comment:
Just out of curiosity, this rule can always make performance better? For
example, how about the case where a right table has too many duplicates?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]