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

codec: Don't convert set or enum datum to float64 when encoding them (#32308) #32351

Closed
Closed
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
14 changes: 14 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8453,3 +8453,17 @@ func (s *testSerialSuite) TestIssue30289(c *C) {
err := tk.QueryToErr("select /*+ hash_join(t1) */ * from t t1 join t t2 on t1.a=t2.a")
c.Assert(err.Error(), Matches, "issue30289 build return error")
}

func (s *testSerialSuite) TestEncodingSet(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("CREATE TABLE `enum-set` (`set` SET(" +
"'x00','x01','x02','x03','x04','x05','x06','x07','x08','x09','x10','x11','x12','x13','x14','x15'," +
"'x16','x17','x18','x19','x20','x21','x22','x23','x24','x25','x26','x27','x28','x29','x30','x31'," +
"'x32','x33','x34','x35','x36','x37','x38','x39','x40','x41','x42','x43','x44','x45','x46','x47'," +
"'x48','x49','x50','x51','x52','x53','x54','x55','x56','x57','x58','x59','x60','x61','x62','x63'" +
")NOT NULL PRIMARY KEY)")
tk.MustExec("INSERT INTO `enum-set` VALUES\n(\"x00,x59\");")
tk.MustQuery("select `set` from `enum-set` use index(PRIMARY)").Check(testkit.Rows("x00,x59"))
tk.MustExec("admin check table `enum-set`")
}
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shirou/gopsutil v2.19.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v3.20.12+incompatible h1:6VEGkOXP/eP4o2Ilk8cSsX0PhOEfX6leqAnD+urrp9M=
Expand Down
12 changes: 6 additions & 6 deletions util/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func encode(sc *stmtctx.StatementContext, b []byte, vals []types.Datum, comparab
err = sc.HandleOverflow(err, err)
}
case types.KindMysqlEnum:
b = encodeUnsignedInt(b, uint64(vals[i].GetMysqlEnum().ToNumber()), comparable)
b = encodeUnsignedInt(b, vals[i].GetMysqlEnum().Value, comparable)
case types.KindMysqlSet:
b = encodeUnsignedInt(b, uint64(vals[i].GetMysqlSet().ToNumber()), comparable)
b = encodeUnsignedInt(b, vals[i].GetMysqlSet().Value, comparable)
case types.KindMysqlBit, types.KindBinaryLiteral:
// We don't need to handle errors here since the literal is ensured to be able to store in uint64 in convertToMysqlBit.
var val uint64
Expand Down Expand Up @@ -156,9 +156,9 @@ func EstimateValueSize(sc *stmtctx.StatementContext, val types.Datum) (int, erro
case types.KindMysqlDecimal:
l = valueSizeOfDecimal(val.GetMysqlDecimal(), val.Length(), val.Frac()) + 1
case types.KindMysqlEnum:
l = valueSizeOfUnsignedInt(uint64(val.GetMysqlEnum().ToNumber()))
l = valueSizeOfUnsignedInt(val.GetMysqlEnum().Value)
case types.KindMysqlSet:
l = valueSizeOfUnsignedInt(uint64(val.GetMysqlSet().ToNumber()))
l = valueSizeOfUnsignedInt(val.GetMysqlSet().Value)
case types.KindMysqlBit, types.KindBinaryLiteral:
val, err := val.GetBinaryLiteral().ToInt(sc)
terror.Log(errors.Trace(err))
Expand Down Expand Up @@ -351,7 +351,7 @@ func encodeHashChunkRowIdx(sc *stmtctx.StatementContext, row chunk.Row, tp *type
}
case mysql.TypeEnum:
flag = compactBytesFlag
v := uint64(row.GetEnum(idx).ToNumber())
v := row.GetEnum(idx).Value
str := ""
if enum, err := types.ParseEnumValue(tp.Elems, v); err == nil {
// str will be empty string if v out of definition of enum.
Expand Down Expand Up @@ -560,7 +560,7 @@ func HashChunkSelected(sc *stmtctx.StatementContext, h []hash.Hash64, chk *chunk
isNull[i] = !ignoreNull
} else {
buf[0] = compactBytesFlag
v := uint64(column.GetEnum(i).ToNumber())
v := column.GetEnum(i).Value
str := ""
if enum, err := types.ParseEnumValue(tp.Elems, v); err == nil {
// str will be empty string if v out of definition of enum.
Expand Down