Skip to content

Commit

Permalink
executor: check unequal handles when buildTableReader4INLJoin (#15675)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu authored Mar 26, 2020
1 parent 7a67ff4 commit 6dd8377
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2603,8 +2603,19 @@ func (builder *dataReaderBuilder) buildTableReaderForIndexJoin(ctx context.Conte
return nil, err
}
handles := make([]int64, 0, len(lookUpContents))
var isValidHandle bool
for _, content := range lookUpContents {
handles = append(handles, content.keys[0].GetInt64())
handle := content.keys[0].GetInt64()
isValidHandle = true
for _, key := range content.keys {
if handle != key.GetInt64() {
isValidHandle = false
break
}
}
if isValidHandle {
handles = append(handles, handle)
}
}
return builder.buildTableReaderFromHandles(ctx, e, handles)
}
Expand Down
10 changes: 10 additions & 0 deletions executor/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,16 @@ func (s *testSuiteJoin1) TestIndexLookupJoin(c *C) {
tk.MustQuery("select /*+ INL_HASH_JOIN(s) */ count(*) from t join s use index(idx) on s.a = t.a and s.b < t.b").Check(testkit.Rows("64"))
tk.MustExec("set @@tidb_index_lookup_join_concurrency=1;")
tk.MustQuery("select /*+ INL_HASH_JOIN(s) */ count(*) from t join s use index(idx) on s.a = t.a and s.b < t.b").Check(testkit.Rows("64"))

// issue15658
tk.MustExec("drop table t1, t2")
tk.MustExec("create table t1(id int primary key)")
tk.MustExec("create table t2(a int, b int)")
tk.MustExec("insert into t1 values(1)")
tk.MustExec("insert into t2 values(1,1),(2,1)")
tk.MustQuery("select /*+ inl_join(t1)*/ * from t1 join t2 on t2.b=t1.id and t2.a=t1.id;").Check(testkit.Rows("1 1 1"))
tk.MustQuery("select /*+ inl_hash_join(t1)*/ * from t1 join t2 on t2.b=t1.id and t2.a=t1.id;").Check(testkit.Rows("1 1 1"))
tk.MustQuery("select /*+ inl_merge_join(t1)*/ * from t1 join t2 on t2.b=t1.id and t2.a=t1.id;").Check(testkit.Rows("1 1 1"))
}

func (s *testSuiteJoin1) TestIndexNestedLoopHashJoin(c *C) {
Expand Down

0 comments on commit 6dd8377

Please sign in to comment.