Skip to content

Commit

Permalink
Merge pull request pingcap#1039 from pingcap/coocood/fix-join-subquery
Browse files Browse the repository at this point in the history
optimizer/plan: check join path subquery when attach condition.
  • Loading branch information
coocood committed Apr 1, 2016
2 parents f8bd285 + 67cdbe2 commit e9ff83a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions optimizer/plan/planbuilder_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ func (p *joinPath) attachEqualCond(eqCon *equalCond, availablePaths []*joinPath)
}
return false
}
// subquery join
if p.subquery != nil {
// TODO: find a way to attach condition to subquery.
return false
}
// outer join
if p.outer.attachEqualCond(eqCon, availablePaths) {
p.filterRate *= rateEqual
Expand Down
12 changes: 12 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,18 @@ func (s *testSessionSuite) TestIgnoreForeignKey(c *C) {
mustExecSQL(c, se, sqlText)
}

func (s *testSessionSuite) TestJoinSubquery(c *C) {
store := newStore(c, s.dbName)
se := newSession(c, store, s.dbName)
mustExecSQL(c, se, "CREATE TABLE table1 (id INTEGER key AUTO_INCREMENT, data VARCHAR(30))")
mustExecSQL(c, se, "CREATE TABLE table2 (id INTEGER key AUTO_INCREMENT, data VARCHAR(30), t1id INTEGER)")
sqlTxt := `SELECT table1.id AS table1_id, table1.data AS table1_data FROM
table1 INNER JOIN (
SELECT table2.id AS id, table2.data AS ata, table2.t1id AS t1id FROM table2
) AS anon_1 ON table1.id = anon_1.t1id;`
mustExecSQL(c, se, sqlTxt)
}

func (s *testSessionSuite) TestGlobalVarAccessor(c *C) {

varName := "max_allowed_packet"
Expand Down

0 comments on commit e9ff83a

Please sign in to comment.