-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26840][SQL] Avoid cost-based join reorder in presence of join hints #23759
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 all commits
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 |
|---|---|---|
|
|
@@ -43,10 +43,10 @@ object CostBasedJoinReorder extends Rule[LogicalPlan] with PredicateHelper { | |
| val result = plan transformDown { | ||
| // Start reordering with a joinable item, which is an InnerLike join with conditions. | ||
| // Avoid reordering if a join hint is present. | ||
| case j @ Join(_, _, _: InnerLike, Some(cond), hint) if hint == JoinHint.NONE => | ||
| case j @ Join(_, _, _: InnerLike, Some(cond), JoinHint.NONE) => | ||
| reorder(j, j.output) | ||
| case p @ Project(projectList, Join(_, _, _: InnerLike, Some(cond), hint)) | ||
| if projectList.forall(_.isInstanceOf[Attribute]) && hint == JoinHint.NONE => | ||
| case p @ Project(projectList, Join(_, _, _: InnerLike, Some(cond), JoinHint.NONE)) | ||
| if projectList.forall(_.isInstanceOf[Attribute]) => | ||
| reorder(p, p.output) | ||
| } | ||
| // After reordering is finished, convert OrderedJoin back to Join. | ||
|
|
@@ -77,12 +77,12 @@ object CostBasedJoinReorder extends Rule[LogicalPlan] with PredicateHelper { | |
| */ | ||
| private def extractInnerJoins(plan: LogicalPlan): (Seq[LogicalPlan], Set[Expression]) = { | ||
| plan match { | ||
| case Join(left, right, _: InnerLike, Some(cond), _) => | ||
| case Join(left, right, _: InnerLike, Some(cond), JoinHint.NONE) => | ||
| val (leftPlans, leftConditions) = extractInnerJoins(left) | ||
| val (rightPlans, rightConditions) = extractInnerJoins(right) | ||
| (leftPlans ++ rightPlans, splitConjunctivePredicates(cond).toSet ++ | ||
| leftConditions ++ rightConditions) | ||
| case Project(projectList, j @ Join(_, _, _: InnerLike, Some(cond), _)) | ||
| case Project(projectList, j @ Join(_, _, _: InnerLike, Some(cond), JoinHint.NONE)) | ||
|
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. Ur, is this required? Eventually, line 80 looks enough for me.
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. It would still be correct without this line of change, but I think it's more efficient that way.
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. This is also not a bug fix. Just to improve it and make it more efficient. |
||
| if projectList.forall(_.isInstanceOf[Attribute]) => | ||
| extractInnerJoins(j) | ||
| case _ => | ||
|
|
@@ -91,11 +91,11 @@ object CostBasedJoinReorder extends Rule[LogicalPlan] with PredicateHelper { | |
| } | ||
|
|
||
| private def replaceWithOrderedJoin(plan: LogicalPlan): LogicalPlan = plan match { | ||
| case j @ Join(left, right, jt: InnerLike, Some(cond), _) => | ||
| case j @ Join(left, right, jt: InnerLike, Some(cond), JoinHint.NONE) => | ||
|
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. Yep. This is the same one which I suggested. |
||
| val replacedLeft = replaceWithOrderedJoin(left) | ||
| val replacedRight = replaceWithOrderedJoin(right) | ||
| OrderedJoin(replacedLeft, replacedRight, jt, Some(cond)) | ||
| case p @ Project(projectList, j @ Join(_, _, _: InnerLike, Some(cond), _)) => | ||
| case p @ Project(projectList, j @ Join(_, _, _: InnerLike, Some(cond), JoinHint.NONE)) => | ||
|
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. This is not needed actually.
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. Same as above. |
||
| p.copy(child = replaceWithOrderedJoin(j)) | ||
| case _ => | ||
| plan | ||
|
|
||
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.
Could you revert these aesthetic changes (line 46 ~ 49) back?
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.
This PR is not for fixing a regression. Actually, it is just a follow-up of #23524. Thus, it is like a PR for code cleaning.