Skip to content

Commit

Permalink
executor: make join work when keys are bigint and bit (pingcap#19032) (
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Sep 17, 2020
1 parent d23d8bd commit 282f852
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
54 changes: 54 additions & 0 deletions executor/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,60 @@ func (s *testSuite2) TestIssue19112(c *C) {
"3 1.010000 3 1.010000"))
}

func (s *testSuite2) TestIssue11896(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)

// 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 *testSuite2) TestIssue19498(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)

Expand Down
8 changes: 2 additions & 6 deletions util/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,13 @@ func encodeHashChunkRow(sc *stmtctx.StatementContext, b []byte, row chunk.Row, a
}
switch allTypes[i].Tp {
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong, mysql.TypeYear:
if !mysql.HasUnsignedFlag(allTypes[i].Flag) {
if !mysql.HasUnsignedFlag(allTypes[i].Flag) && row.GetInt64(i) < 0 {
b = encodeSignedInt(b, row.GetInt64(i), comparable)
break
}
// encode unsigned integers.
integer := row.GetInt64(i)
if integer < 0 {
b = encodeUnsignedInt(b, uint64(integer), comparable)
} else {
b = encodeSignedInt(b, integer, comparable)
}
b = encodeUnsignedInt(b, uint64(integer), comparable)
case mysql.TypeFloat:
b = append(b, floatFlag)
b = EncodeFloat(b, float64(row.GetFloat32(i)))
Expand Down

0 comments on commit 282f852

Please sign in to comment.