From a530575f3675339373ff5d5579eff1f94004e54c Mon Sep 17 00:00:00 2001 From: crazycs Date: Wed, 22 Aug 2018 09:15:09 +0800 Subject: [PATCH] ddl: fix admin bug by unflatten clear i. cherry-pick from #7359. (#7457) --- executor/executor_test.go | 9 +++++++++ tablecodec/tablecodec.go | 2 ++ 2 files changed, 11 insertions(+) diff --git a/executor/executor_test.go b/executor/executor_test.go index 805953740bb87..855fb6cede171 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -234,6 +234,15 @@ func (s *testSuite) TestAdmin(c *C) { // For "checksum_with_index", we have two checksums, so the result will be 1^1 = 0. // For "checksum_without_index", we only have one checksum, so the result will be 1. res.Sort().Check(testkit.Rows("test checksum_with_index 0 2 2", "test checksum_without_index 1 1 1")) + + tk.MustExec("drop table if exists t1;") + tk.MustExec("CREATE TABLE t1 (c2 BOOL, PRIMARY KEY (c2));") + tk.MustExec("INSERT INTO t1 SET c2 = '0';") + tk.MustExec("ALTER TABLE t1 ADD COLUMN c3 DATETIME NULL DEFAULT '2668-02-03 17:19:31';") + tk.MustExec("ALTER TABLE t1 ADD INDEX idx2 (c3);") + tk.MustExec("ALTER TABLE t1 ADD COLUMN c4 bit(10) default 127;") + tk.MustExec("ALTER TABLE t1 ADD INDEX idx3 (c4);") + tk.MustExec("admin check table t1;") } func (s *testSuite) fillData(tk *testkit.TestKit, table string) { diff --git a/tablecodec/tablecodec.go b/tablecodec/tablecodec.go index 2c971aa34b90e..1afe4d9de456f 100644 --- a/tablecodec/tablecodec.go +++ b/tablecodec/tablecodec.go @@ -422,6 +422,7 @@ func unflatten(datum types.Datum, ft *types.FieldType, loc *time.Location) (type return datum, errors.Trace(err) } } + datum.SetUint64(0) datum.SetMysqlTime(t) return datum, nil case mysql.TypeDuration: //duration should read fsp from column meta data @@ -446,6 +447,7 @@ func unflatten(datum types.Datum, ft *types.FieldType, loc *time.Location) (type case mysql.TypeBit: val := datum.GetUint64() byteSize := (ft.Flen + 7) >> 3 + datum.SetUint64(0) datum.SetMysqlBit(types.NewBinaryLiteralFromUint(val, byteSize)) } return datum, nil