Skip to content

Commit

Permalink
plan: always chose the smaller child as outer for IndexJoin (pingcap#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason committed Aug 1, 2018
1 parent cd405d7 commit 2f70b36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions plan/gen_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ func (p *LogicalJoin) tryToGetIndexJoin(prop *requiredProp) ([]PhysicalPlan, boo
plans = append(plans, join...)
}
case InnerJoin:
lhsCardinality := p.Children()[0].statsInfo().Count()
rhsCardinality := p.Children()[1].statsInfo().Count()
lhsCardinality := p.Children()[0].StatsInfo().Count()
rhsCardinality := p.Children()[1].StatsInfo().Count()

leftJoins := p.getIndexJoinByOuterIdx(prop, 0)
if leftOuter && leftJoins != nil {
Expand Down
10 changes: 7 additions & 3 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type Plan interface {
replaceExprColumns(replace map[string]*expression.Column)

context() sessionctx.Context

// StatsInfo will return the statsInfo for this plan.
StatsInfo() *statsInfo
}

// taskType is the type of execution task.
Expand Down Expand Up @@ -205,9 +208,6 @@ type PhysicalPlan interface {
// getChildReqProps gets the required property by child index.
getChildReqProps(idx int) *requiredProp

// StatsInfo will return the statsInfo for this plan.
StatsInfo() *statsInfo

// Get all the children.
Children() []PhysicalPlan

Expand Down Expand Up @@ -270,6 +270,10 @@ func (p *baseLogicalPlan) buildKeyInfo() {
}
}

func (p *DataSource) StatsInfo() *statsInfo {
return p.statsAfterSelect
}

func newBasePlan(ctx sessionctx.Context, tp string) basePlan {
ctx.GetSessionVars().PlanID++
id := ctx.GetSessionVars().PlanID
Expand Down
2 changes: 1 addition & 1 deletion plan/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *statsInfo) scaleByExpectCnt(expectCnt float64) *statsInfo {
return s
}

func (p *basePhysicalPlan) StatsInfo() *statsInfo {
func (p *basePlan) StatsInfo() *statsInfo {
return p.stats
}

Expand Down

0 comments on commit 2f70b36

Please sign in to comment.