Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: check unequal handles when buildTableReader4INLJoin (#15675) #15734

Merged
merged 3 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2114,8 +2114,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()
Copy link
Contributor

@fzhedu fzhedu Apr 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is only one keys in each content, properly true in most cases, it is no need to use this loop.

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 @@ -903,6 +903,16 @@ func (s *testSuite2) TestIndexLookupJoin(c *C) {
tk.MustQuery("select /*+ TIDB_INLJ(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 /*+ TIDB_INLJ(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 *testSuite2) TestMergejoinOrder(c *C) {
Expand Down