-
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 #6996
Conversation
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.
LGTM
plan/plan.go
Outdated
@@ -320,6 +323,13 @@ type basePlan struct { | |||
stats *statsInfo | |||
} | |||
|
|||
func (p *basePlan) cardinality() float64 { | |||
if p.stats == nil { | |||
return math.MaxFloat64 |
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.
Why return MaxFloat64 here?
@@ -163,6 +164,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 comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment for it.
@@ -385,22 +385,30 @@ func (p *LogicalJoin) tryToGetIndexJoin(prop *requiredProp) ([]PhysicalPlan, boo | |||
plans = append(plans, join...) | |||
} | |||
case InnerJoin: | |||
join := p.getIndexJoinByOuterIdx(prop, 0) | |||
if join != nil { | |||
lhsCardinality := p.Children()[0].cardinality() |
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.
Can we move this to line 402?
if p.stats == nil { | ||
return math.MaxFloat64 | ||
} | ||
return p.stats.count |
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.
It is not cardinality, cardinality is the number of elements in a set.
@@ -163,6 +164,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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add getStats
instead?
Then use the count
to determine the outer table.
What have you changed? (mandatory)
Always chose the smaller child as the outer one for
IndexJoin
if possible.What are the type of the changes (mandatory)?
How has this PR been tested (mandatory)?