Skip to content

Commit

Permalink
optimizer: fix a bug in optimizeJoinOrder
Browse files Browse the repository at this point in the history
Fix a bug in optimizeJoinOrder.
  • Loading branch information
zxylvlp committed Mar 16, 2016
1 parent 864c978 commit 953c664
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 12 additions & 0 deletions optimizer/plan/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,18 @@ func (s *testPlanSuite) TestJoinPath(c *C) {
on t1.i1 = 1 and t1.c1 = t2.i2`,
"InnerJoin{Index(t1.i1)->OuterJoin{InnerJoin{Index(t2.i2)->Index(t3.i3)}->Index(t4.i4)}}->Fields",
},
{
`select * from
t1 join (
t2 left join (
t3 join t4
on t3.i3 = t4.c4
)
on t2.i2 = t3.c3
)
on t1.i1 = t2.c2`,
"InnerJoin{OuterJoin{Table(t2)->InnerJoin{Table(t4)->Index(t3.i3)}}->Index(t1.i1)}->Fields",
},
{
`select * from
t1 join (
Expand Down
4 changes: 1 addition & 3 deletions optimizer/plan/planbuilder_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func (p *joinPath) optimizeJoinOrder(availablePaths []*joinPath) {
}
for len(pathMap) > 0 {
next := p.nextPath(pathMap, availablePaths)
next.optimizeJoinOrder(availablePaths)
ordered = append(ordered, next)
delete(pathMap, next)
availablePaths = append(availablePaths, next)
Expand All @@ -456,9 +457,6 @@ func (p *joinPath) optimizeJoinOrder(availablePaths []*joinPath) {
}
}
p.reattach(pathMap, availablePaths)
for path := range pathMap {
path.optimizeJoinOrder(availablePaths)
}
}
p.inners = ordered
}
Expand Down

0 comments on commit 953c664

Please sign in to comment.