Skip to content

Commit

Permalink
executor: stable the show stats_locked output (#47182)
Browse files Browse the repository at this point in the history
ref #46351
  • Loading branch information
Rustin170506 authored Sep 22, 2023
1 parent 2472154 commit 3c8fe0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions executor/show_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ func (e *ShowExec) fetchShowStatsLocked() error {
return err
}

// Sort the table IDs to make the output stable.
slices.Sort(tids)
for _, tid := range tids {
if _, ok := lockedTables[tid]; ok {
info := tableInfo[tid]
Expand Down
14 changes: 9 additions & 5 deletions executor/show_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ func TestShowStatsLocked(t *testing.T) {

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t, t1")
tk.MustExec("drop table if exists t, t1, a1, dc")
tk.MustExec("create table t (a int, b int)")
tk.MustExec("create table t1 (a int, b int)")
tk.MustExec("lock stats t, t1")
tk.MustExec("create table a1 (a int, b int)")
tk.MustExec("create table dc (a int, b int)")
tk.MustExec("lock stats t, t1, a1, dc")
result := tk.MustQuery("show stats_locked").Sort()
require.Len(t, result.Rows(), 2)
require.Equal(t, "t", result.Rows()[0][1])
require.Equal(t, "t1", result.Rows()[1][1])
require.Len(t, result.Rows(), 4)
require.Equal(t, "a1", result.Rows()[0][1])
require.Equal(t, "dc", result.Rows()[1][1])
require.Equal(t, "t", result.Rows()[2][1])
require.Equal(t, "t1", result.Rows()[3][1])
result = tk.MustQuery("show stats_locked where table_name = 't'")
require.Len(t, result.Rows(), 1)
require.Equal(t, "t", result.Rows()[0][1])
Expand Down

0 comments on commit 3c8fe0f

Please sign in to comment.