From 8c97eddad5b1a490a4e6e94c2079ed64ebb20a22 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Fri, 22 Sep 2023 11:29:59 +0800 Subject: [PATCH] executor: stable the show stats_locked output --- executor/show_stats.go | 2 ++ executor/show_stats_test.go | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/executor/show_stats.go b/executor/show_stats.go index d72affdfda5a6..d017e871f143f 100644 --- a/executor/show_stats.go +++ b/executor/show_stats.go @@ -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] diff --git a/executor/show_stats_test.go b/executor/show_stats_test.go index 7a24d4a693df3..e3e3a0d13d635 100644 --- a/executor/show_stats_test.go +++ b/executor/show_stats_test.go @@ -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])