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: fix index join panic on prefix index on some cases (#24568) #29217

Merged
merged 5 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions executor/index_lookup_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,11 @@ func (iw *innerWorker) constructLookupContent(task *lookUpJoinTask) ([]*indexJoi
// Store the encoded lookup key in chunk, so we can use it to lookup the matched inners directly.
task.encodedLookUpKeys[chkIdx].AppendBytes(0, keyBuf)
if iw.hasPrefixCol {
for i := range iw.outerCtx.keyCols {
for i, outerOffset := range iw.keyOff2IdxOff {
// If it's a prefix column. Try to fix it.
if iw.colLens[iw.keyCols[i]] != types.UnspecifiedLength {
ranger.CutDatumByPrefixLen(&dLookUpKey[i], iw.colLens[iw.keyCols[i]], iw.rowTypes[iw.keyCols[i]])
joinKeyColPrefixLen := iw.colLens[outerOffset]
if joinKeyColPrefixLen != types.UnspecifiedLength {
ranger.CutDatumByPrefixLen(&dLookUpKey[i], joinKeyColPrefixLen, iw.rowTypes[iw.keyCols[i]])
}
}
// dLookUpKey is sorted and deduplicated at sortAndDedupLookUpContents.
Expand Down
12 changes: 12 additions & 0 deletions executor/index_lookup_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,15 @@ func (s *testSuite5) TestIssue23656(c *C) {
"1 clever jang 1 clever jang",
"2 blissful aryabhata 2 blissful aryabhata"))
}

func (s *testSuite5) TestIssue24547(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists a")
tk.MustExec("drop table if exists b")
tk.MustExec("CREATE TABLE `a` (\n `v` varchar(100) DEFAULT NULL,\n `k1` varchar(100) NOT NULL,\n `k2` varchar(100) NOT NULL,\n PRIMARY KEY (`k1`(3),`k2`(3)) /*T![clustered_index] CLUSTERED */,\n KEY `kk2` (`k2`(3)),\n UNIQUE KEY `uk1` (`v`)\n)")
tk.MustExec("CREATE TABLE `b` (\n `v` varchar(100) DEFAULT NULL,\n `k1` varchar(100) NOT NULL,\n `k2` varchar(100) NOT NULL,\n PRIMARY KEY (`k1`(3),`k2`(3)) /*T![clustered_index] CLUSTERED */,\n KEY `kk2` (`k2`(3))\n)")
tk.MustExec("insert into a(v, k1, k2) values('1', '1', '1'), ('22', '22', '22'), ('333', '333', '333'), ('3444', '3444', '3444'), ('444', '444', '444')")
tk.MustExec("insert into b(v, k1, k2) values('1', '1', '1'), ('22', '22', '22'), ('333', '333', '333'), ('2333', '2333', '2333'), ('555', '555', '555')")
tk.MustExec("delete a from a inner join b on a.k1 = b.k1 and a.k2 = b.k2 where b.k2 <> '333'")
}