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 the bug: can not join if join keys are type bigint and type bit (#19032) #19215

Merged
merged 6 commits into from
Sep 1, 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
60 changes: 51 additions & 9 deletions executor/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2171,16 +2171,58 @@ func (s *testSuite9) TestIssue18572_3(c *C) {
c.Assert(strings.Contains(err.Error(), "mockIndexHashJoinBuildErr"), IsTrue)
}

func (s *testSuite9) TestIssue19112(c *C) {
func (s *testSuiteJoin3) TestIssue11896(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1 ( c_int int, c_decimal decimal(12, 6), key(c_int), unique key(c_decimal) )")
tk.MustExec("create table t2 like t1")
tk.MustExec("insert into t1 (c_int, c_decimal) values (1, 4.064000), (2, 0.257000), (3, 1.010000)")
tk.MustExec("insert into t2 (c_int, c_decimal) values (1, 4.064000), (3, 1.010000)")
tk.MustQuery("select /*+ HASH_JOIN(t1,t2) */ * from t1 join t2 on t1.c_decimal = t2.c_decimal order by t1.c_int").Check(testkit.Rows(
"1 4.064000 1 4.064000",
"3 1.010000 3 1.010000"))

// compare bigint to bit(64)
tk.MustExec("drop table if exists t")
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t(c1 bigint)")
tk.MustExec("create table t1(c1 bit(64))")
tk.MustExec("insert into t value(1)")
tk.MustExec("insert into t1 value(1)")
tk.MustQuery("select * from t, t1 where t.c1 = t1.c1").Check(
testkit.Rows("1 \x00\x00\x00\x00\x00\x00\x00\x01"))

// compare int to bit(32)
tk.MustExec("drop table if exists t")
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t(c1 int)")
tk.MustExec("create table t1(c1 bit(32))")
tk.MustExec("insert into t value(1)")
tk.MustExec("insert into t1 value(1)")
tk.MustQuery("select * from t, t1 where t.c1 = t1.c1").Check(
testkit.Rows("1 \x00\x00\x00\x01"))

// compare mediumint to bit(24)
tk.MustExec("drop table if exists t")
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t(c1 mediumint)")
tk.MustExec("create table t1(c1 bit(24))")
tk.MustExec("insert into t value(1)")
tk.MustExec("insert into t1 value(1)")
tk.MustQuery("select * from t, t1 where t.c1 = t1.c1").Check(
testkit.Rows("1 \x00\x00\x01"))

// compare smallint to bit(16)
tk.MustExec("drop table if exists t")
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t(c1 smallint)")
tk.MustExec("create table t1(c1 bit(16))")
tk.MustExec("insert into t value(1)")
tk.MustExec("insert into t1 value(1)")
tk.MustQuery("select * from t, t1 where t.c1 = t1.c1").Check(
testkit.Rows("1 \x00\x01"))

// compare tinyint to bit(8)
tk.MustExec("drop table if exists t")
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t(c1 tinyint)")
tk.MustExec("create table t1(c1 bit(8))")
tk.MustExec("insert into t value(1)")
tk.MustExec("insert into t1 value(1)")
tk.MustQuery("select * from t, t1 where t.c1 = t1.c1").Check(
testkit.Rows("1 \x01"))
}

func (s *testSuiteJoin3) TestIssue19498(c *C) {
Expand Down
14 changes: 6 additions & 8 deletions util/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,9 @@ func encodeHashChunkRowIdx(sc *stmtctx.StatementContext, row chunk.Row, tp *type
}
switch tp.Tp {
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong, mysql.TypeYear:
flag = varintFlag
if mysql.HasUnsignedFlag(tp.Flag) {
if integer := row.GetInt64(idx); integer < 0 {
flag = uvarintFlag
}
flag = uvarintFlag
if !mysql.HasUnsignedFlag(tp.Flag) && row.GetInt64(idx) < 0 {
flag = varintFlag
}
b = row.GetRaw(idx)
case mysql.TypeFloat:
Expand Down Expand Up @@ -406,9 +404,9 @@ func HashChunkSelected(sc *stmtctx.StatementContext, h []hash.Hash64, chk *chunk
buf[0], b = NilFlag, nil
isNull[i] = true
} else {
buf[0] = varintFlag
if mysql.HasUnsignedFlag(tp.Flag) && v < 0 {
buf[0] = uvarintFlag
buf[0] = uvarintFlag
if !mysql.HasUnsignedFlag(tp.Flag) && v < 0 {
buf[0] = varintFlag
}
b = column.GetRaw(i)
}
Expand Down