-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
plan: always chose the smaller child as outer for IndexJoin #7019
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
441e0fe
plan: always chose the smaller child as outer for IndexJoin
zz-jason da1e12c
Merge branch 'master' into dev/master-indexjoin
ngaut a52ba2c
Merge branch 'master' into dev/master-indexjoin
zz-jason 041929e
address comment
zz-jason 73f5232
Merge branch 'master' into dev/master-indexjoin
winoros ecf1f05
Merge branch 'master' into dev/master-indexjoin
zz-jason d16938c
Merge branch 'master' into dev/master-indexjoin
zz-jason 270b84a
Merge branch 'master' into dev/master-indexjoin
zz-jason File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -519,22 +519,29 @@ func (p *LogicalJoin) tryToGetIndexJoin(prop *requiredProp) ([]PhysicalPlan, boo | |
plans = append(plans, join...) | ||
} | ||
case InnerJoin: | ||
join := p.getIndexJoinByOuterIdx(prop, 0) | ||
if join != nil { | ||
// If the plan is not nil and matches the hint, return it directly. | ||
if leftOuter { | ||
return join, true | ||
} | ||
plans = append(plans, join...) | ||
lhsCardinality := p.Children()[0].cardinality() | ||
rhsCardinality := p.Children()[1].cardinality() | ||
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. ditto |
||
|
||
leftJoins := p.getIndexJoinByOuterIdx(prop, 0) | ||
if leftOuter && leftJoins != nil { | ||
return leftJoins, true | ||
} | ||
join = p.getIndexJoinByOuterIdx(prop, 1) | ||
if join != nil { | ||
// If the plan is not nil and matches the hint, return it directly. | ||
if rightOuter { | ||
return join, true | ||
} | ||
plans = append(plans, join...) | ||
|
||
rightJoins := p.getIndexJoinByOuterIdx(prop, 1) | ||
if rightOuter && rightJoins != nil { | ||
return rightJoins, true | ||
} | ||
|
||
if leftJoins != nil && lhsCardinality < rhsCardinality { | ||
return leftJoins, leftOuter | ||
} | ||
|
||
if rightJoins != nil && rhsCardinality < lhsCardinality { | ||
return rightJoins, rightOuter | ||
} | ||
|
||
plans = append(plans, leftJoins...) | ||
plans = append(plans, rightJoins...) | ||
} | ||
return plans, false | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,8 @@ type LogicalPlan interface { | |
// deriveStats derives statistic info between plans. | ||
deriveStats() (*statsInfo, error) | ||
|
||
cardinality() float64 | ||
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. We don't need this. |
||
|
||
// preparePossibleProperties is only used for join and aggregation. Like group by a,b,c, all permutation of (a,b,c) is | ||
// valid, but the ordered indices in leaf plan is limited. So we can get all possible order properties by a pre-walking. | ||
// Please make sure that children's method is called though we may not need its return value, | ||
|
@@ -324,6 +326,20 @@ func (p *baseLogicalPlan) extractCorrelatedCols() []*expression.CorrelatedColumn | |
return corCols | ||
} | ||
|
||
func (p *DataSource) cardinality() float64 { | ||
if p.statsAfterSelect == nil { | ||
return math.MaxFloat64 | ||
} | ||
return p.statsAfterSelect.count | ||
} | ||
|
||
func (p *baseLogicalPlan) cardinality() float64 { | ||
if p.stats == nil { | ||
return math.MaxFloat64 | ||
} | ||
return p.stats.count | ||
} | ||
|
||
// PruneColumns implements LogicalPlan interface. | ||
func (p *baseLogicalPlan) PruneColumns(parentUsedCols []*expression.Column) { | ||
if len(p.children) == 0 { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Merge master and you can use
p.Childrend()[0].StatsInfo().Count()
now.