Skip to content

Commit

Permalink
executor: fix index join on prefix column index (#23678) (#23691)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored May 8, 2021
1 parent e431c06 commit f159b62
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions executor/index_lookup_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ func (iw *innerWorker) constructLookupContent(task *lookUpJoinTask) ([]*indexJoi
if iw.hasPrefixCol {
for i := range iw.outerCtx.keyCols {
// If it's a prefix column. Try to fix it.
if iw.colLens[i] != types.UnspecifiedLength {
ranger.CutDatumByPrefixLen(&dLookUpKey[i], iw.colLens[i], iw.rowTypes[iw.keyCols[i]])
if iw.colLens[iw.keyCols[i]] != types.UnspecifiedLength {
ranger.CutDatumByPrefixLen(&dLookUpKey[i], iw.colLens[iw.keyCols[i]], iw.rowTypes[iw.keyCols[i]])
}
}
// dLookUpKey is sorted and deduplicated at sortAndDedupLookUpContents.
Expand Down
25 changes: 25 additions & 0 deletions executor/index_lookup_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,28 @@ func (s *testSuite5) TestIndexJoinEnumSetIssue19233(c *C) {
}
}
}

func (s *testSuite5) TestIssue23653(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1 (c_int int, c_str varchar(40), primary key(c_str), unique key(c_int), unique key(c_str))")
tk.MustExec("create table t2 (c_int int, c_str varchar(40), primary key(c_int, c_str(4)), key(c_int), unique key(c_str))")
tk.MustExec("insert into t1 values (1, 'cool buck'), (2, 'reverent keller')")
tk.MustExec("insert into t2 select * from t1")
tk.MustQuery("select /*+ inl_join(t2) */ * from t1, t2 where t1.c_str = t2.c_str and t1.c_int = t2.c_int and t1.c_int = 2").Check(testkit.Rows(
"2 reverent keller 2 reverent keller"))
}

func (s *testSuite5) TestIssue23656(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1 (c_int int, c_str varchar(40), primary key(c_int, c_str(4)))")
tk.MustExec("create table t2 like t1")
tk.MustExec("insert into t1 values (1, 'clever jang'), (2, 'blissful aryabhata')")
tk.MustExec("insert into t2 select * from t1")
tk.MustQuery("select /*+ inl_join(t2) */ * from t1 join t2 on t1.c_str = t2.c_str where t1.c_int = t2.c_int;").Check(testkit.Rows(
"1 clever jang 1 clever jang",
"2 blissful aryabhata 2 blissful aryabhata"))
}

0 comments on commit f159b62

Please sign in to comment.