Skip to content

Commit

Permalink
executor: do not build range for NullOuterVal in IndexLookUpJoin (pin…
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu committed Nov 29, 2018
1 parent 011529f commit 536e17e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion executor/index_lookup_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,12 @@ func (iw *innerWorker) constructDatumLookupKey(task *lookUpJoinTask, rowIdx int)
dLookupKey := make([]types.Datum, 0, keyLen)
for i, keyCol := range iw.outerCtx.keyCols {
outerValue := outerRow.GetDatum(keyCol, iw.outerCtx.rowTypes[keyCol])

// Join-on-condition can be promised to be equal-condition in
// IndexNestedLoopJoin, thus the filter will always be false if
// outerValue is null, and we don't need to lookup it.
if outerValue.IsNull() {
return nil, nil
}
innerColType := iw.rowTypes[iw.keyCols[i]]
innerValue, err := outerValue.ConvertTo(sc, innerColType)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions executor/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,23 @@ func (s *testSuite) TestIndexLookupJoin(c *C) {
`1 5 1 1`,
`1 6 1 2`,
))

tk.MustExec(`drop table if exists t1, t2, t3;`)
tk.MustExec("create table t1(a int primary key, b int)")
tk.MustExec("insert into t1 values(1, 0), (2, null)")
tk.MustExec("create table t2(a int primary key)")
tk.MustExec("insert into t2 values(0)")
tk.MustQuery("select /*+ TIDB_INLJ(t2)*/ * from t1 left join t2 on t1.b = t2.a;").Check(testkit.Rows(
`1 0 0`,
`2 <nil> <nil>`,
))

tk.MustExec("create table t3(a int, key(a))")
tk.MustExec("insert into t3 values(0)")
tk.MustQuery("select /*+ TIDB_INLJ(t3)*/ * from t1 left join t3 on t1.b = t3.a;").Check(testkit.Rows(
`1 0 0`,
`2 <nil> <nil>`,
))
}

func (s *testSuite) TestMergejoinOrder(c *C) {
Expand Down

0 comments on commit 536e17e

Please sign in to comment.