Skip to content

Commit

Permalink
This is an automated cherry-pick of #49945
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
AilinKid authored and ti-chi-bot committed Jan 2, 2024
1 parent 721bb1a commit b45d9b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions executor/show_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions util/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
Expand Down

0 comments on commit b45d9b2

Please sign in to comment.