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

util: fix a encode bug causes the wrong result of ... (#18855) #18859

Merged
merged 2 commits into from
Jul 29, 2020
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
18 changes: 18 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6690,6 +6690,24 @@ func (s *testIntegrationSerialSuite) TestIssue18702(c *C) {
tk.MustQuery("SELECT * FROM t FORCE INDEX(idx_bc);").Check(testkit.Rows("1 A 10 1", "2 B 20 1"))
}

func (s *testIntegrationSuite) TestIssue18850(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t, t1")
tk.MustExec("create table t(a int, b enum('A', 'B'));")
tk.MustExec("create table t1(a1 int, b1 enum('B', 'A'));")
tk.MustExec("insert into t values (1, 'A');")
tk.MustExec("insert into t1 values (1, 'A');")
tk.MustQuery("select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1;").Check(testkit.Rows("1 A 1 A"))

tk.MustExec("drop table t, t1")
tk.MustExec("create table t(a int, b set('A', 'B'));")
tk.MustExec("create table t1(a1 int, b1 set('B', 'A'));")
tk.MustExec("insert into t values (1, 'A');")
tk.MustExec("insert into t1 values (1, 'A');")
tk.MustQuery("select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1;").Check(testkit.Rows("1 A 1 A"))
}

func (s *testIntegrationSerialSuite) TestIssue18662(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
Expand Down
20 changes: 12 additions & 8 deletions util/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,15 @@ func encodeHashChunkRowIdx(sc *stmtctx.StatementContext, row chunk.Row, tp *type
return
}
case mysql.TypeEnum:
flag = uvarintFlag
flag = compactBytesFlag
v := uint64(row.GetEnum(idx).ToNumber())
b = (*[8]byte)(unsafe.Pointer(&v))[:]
str := tp.Elems[v-1]
b = ConvertByCollation(hack.Slice(str), tp)
case mysql.TypeSet:
flag = uvarintFlag
flag = compactBytesFlag
v := uint64(row.GetSet(idx).ToNumber())
b = (*[unsafe.Sizeof(v)]byte)(unsafe.Pointer(&v))[:]
str := tp.Elems[v-1]
b = ConvertByCollation(hack.Slice(str), tp)
case mysql.TypeBit:
// We don't need to handle errors here since the literal is ensured to be able to store in uint64 in convertToMysqlBit.
flag = uvarintFlag
Expand Down Expand Up @@ -567,9 +569,10 @@ func HashChunkSelected(sc *stmtctx.StatementContext, h []hash.Hash64, chk *chunk
buf[0], b = NilFlag, nil
isNull[i] = true
} else {
buf[0] = uvarintFlag
buf[0] = compactBytesFlag
v := uint64(column.GetEnum(i).ToNumber())
b = (*[sizeUint64]byte)(unsafe.Pointer(&v))[:]
str := tp.Elems[v-1]
b = ConvertByCollation(hack.Slice(str), tp)
}

// As the golang doc described, `Hash.Write` never returns an error.
Expand All @@ -586,9 +589,10 @@ func HashChunkSelected(sc *stmtctx.StatementContext, h []hash.Hash64, chk *chunk
buf[0], b = NilFlag, nil
isNull[i] = true
} else {
buf[0] = uvarintFlag
buf[0] = compactBytesFlag
v := uint64(column.GetSet(i).ToNumber())
b = (*[sizeUint64]byte)(unsafe.Pointer(&v))[:]
str := tp.Elems[v-1]
b = ConvertByCollation(hack.Slice(str), tp)
}

// As the golang doc described, `Hash.Write` never returns an error.
Expand Down