diff --git a/executor/show_stats_test.go b/executor/show_stats_test.go index f48fe9988649d..a88d7e169f04a 100644 --- a/executor/show_stats_test.go +++ b/executor/show_stats_test.go @@ -123,6 +123,25 @@ func TestShowStatsBuckets(t *testing.T) { result.Check(testkit.Rows("test t idx 1 0 1 1 (2020-01-01 00:00:00, 1) (2020-01-01 00:00:00, 1) 0")) } +func TestShowStatsBucketWithDateNullValue(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a datetime, b int, index ia(a,b));") + tk.MustExec("insert into t value('2023-12-27',1),(null, 2),('2023-12-28',3),(null,4);") + tk.MustExec("analyze table t with 0 topn;") + tk.MustQuery("explain format=\"brief\" select * from t where a > 1;").Check(testkit.Rows( + "IndexReader 3.20 root index:Selection", + "└─Selection 3.20 cop[tikv] gt(cast(test.t.a, double BINARY), 1)", + " └─IndexFullScan 4.00 cop[tikv] table:t, index:ia(a, b) keep order:false")) + tk.MustQuery("show stats_buckets where db_name = 'test' and Column_name = 'ia';").Check(testkit.Rows( + "test t ia 1 0 1 1 (NULL, 2) (NULL, 2) 0", + "test t ia 1 1 2 1 (NULL, 4) (NULL, 4) 0", + "test t ia 1 2 3 1 (2023-12-27 00:00:00, 1) (2023-12-27 00:00:00, 1) 0", + "test t ia 1 3 4 1 (2023-12-28 00:00:00, 3) (2023-12-28 00:00:00, 3) 0")) +} + func TestShowStatsHasNullValue(t *testing.T) { store, clean := testkit.CreateMockStore(t) defer clean() diff --git a/util/codec/codec.go b/util/codec/codec.go index 592fa3a18dc01..6a8801a1b84a9 100644 --- a/util/codec/codec.go +++ b/util/codec/codec.go @@ -881,6 +881,7 @@ func DecodeAsDateTime(b []byte, tp byte, loc *time.Location) (remain []byte, d t case uintFlag: var v uint64 b, v, err = DecodeUint(b) +<<<<<<< HEAD:util/codec/codec.go if err != nil { return b, d, err } @@ -895,6 +896,15 @@ func DecodeAsDateTime(b []byte, tp byte, loc *time.Location) (remain []byte, d t } d.SetMysqlTime(t) } +======= + case uvarintFlag: + // Datetime can be encoded as Uvarint + b, v, err = DecodeUvarint(b) + case NilFlag: + // null value should also be decoded out. + return b, d, nil + +>>>>>>> a6ba2ec8a87 (planner: fix show stats_bucket couldn't decode index boundary out (#49945)):pkg/util/codec/codec.go default: return b, d, errors.Errorf("invalid encoded key flag %v", flag) }