From 2edd25c50a3e5919d375ba646e4d0ab6bd8b1dc0 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Wed, 29 Jul 2020 14:12:10 +0800 Subject: [PATCH] cherry pick #18855 to release-4.0 Signed-off-by: ti-srebot --- expression/integration_test.go | 18 ++++++++++++++++++ util/codec/codec.go | 20 ++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index bbb93b5b4c621..bfa60f72d90aa 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -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) diff --git a/util/codec/codec.go b/util/codec/codec.go index 419c268e2b814..3da99782cc386 100644 --- a/util/codec/codec.go +++ b/util/codec/codec.go @@ -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 @@ -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. @@ -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.