-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-34014][SQL] Ignore Distinct if it is the right child of a left semi or anti join #31045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,7 +176,7 @@ abstract class Optimizer(catalogManager: CatalogManager) | |
| // to enforce idempotence on it and we change this batch from Once to FixedPoint(1). | ||
| Batch("Subquery", FixedPoint(1), | ||
| OptimizeSubqueries) :: | ||
| Batch("Replace Operators", fixedPoint, | ||
| Batch("Replace Operators", Once, | ||
| RewriteExceptAll, | ||
| RewriteIntersectAll, | ||
| ReplaceIntersectWithSemiJoin, | ||
|
|
@@ -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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I benchmarked a bit and you are right - this can cause a performance regression. For example q87 took a 10% hit on sf100. I think it's best to close this PR and issue. |
||
| case Distinct(child) => Aggregate(child.output, child.output, child) | ||
| } | ||
| } | ||
|
|
||
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could you move this comment between L1619/L1620?