From 886650b58265039ad8492f7b0b454aee81293ba3 Mon Sep 17 00:00:00 2001 From: Ziqian Qin Date: Tue, 15 Feb 2022 14:31:38 +0800 Subject: [PATCH] codec: Don't convert set or enum datum to float64 when encoding them (#32308) close pingcap/tidb#32302 --- executor/executor_test.go | 14 ++++++++++++++ util/codec/codec.go | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/executor/executor_test.go b/executor/executor_test.go index 0bb7600f1b044..8010157a9fc18 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -9856,3 +9856,17 @@ func (s *testSerialSuite) TestFix31537(c *C) { );`) tk.MustQuery(`trace plan SELECT T_ID, T_S_SYMB, T_QTY, ST_NAME, TH_DTS FROM ( SELECT T_ID AS ID FROM TRADE WHERE T_CA_ID = 43000014236 ORDER BY T_DTS DESC LIMIT 10 ) T, TRADE, TRADE_HISTORY, STATUS_TYPE WHERE TRADE.T_ID = ID AND TRADE_HISTORY.TH_T_ID = TRADE.T_ID AND STATUS_TYPE.ST_ID = TRADE_HISTORY.TH_ST_ID ORDER BY TH_DTS DESC LIMIT 30;`) } + +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`") +} diff --git a/util/codec/codec.go b/util/codec/codec.go index aa318d09f09b6..cdb586c68c85e 100644 --- a/util/codec/codec.go +++ b/util/codec/codec.go @@ -116,9 +116,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