Skip to content

Commit

Permalink
cherry pick pingcap#18855 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
wjhuang2016 authored and ti-srebot committed Jul 29, 2020
1 parent 2e3db79 commit 2edd25c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
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

0 comments on commit 2edd25c

Please sign in to comment.