Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: show cmd to check if all needed histograms are loaded #29672

Merged
merged 10 commits into from
Dec 10, 2021
3 changes: 3 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ func (e *ShowExec) fetchAll(ctx context.Context) error {
case ast.ShowStatsHealthy:
e.fetchShowStatsHealthy()
return nil
case ast.ShowHistogramsInFlight:
e.fetchShowHistogramsInFlight()
return nil
case ast.ShowColumnStatsUsage:
return e.fetchShowColumnStatsUsage()
case ast.ShowPlugins:
Expand Down
4 changes: 4 additions & 0 deletions executor/show_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ func (e *ShowExec) appendTableForStatsHealthy(dbName, tblName, partitionName str
})
}

func (e *ShowExec) fetchShowHistogramsInFlight() {
e.appendRow([]interface{}{statistics.HistogramNeededColumns.Length()})
}

func (e *ShowExec) fetchShowAnalyzeStatus() {
rows := dataForAnalyzeStatusHelper(e.baseExecutor.ctx)
for _, row := range rows {
Expand Down
13 changes: 13 additions & 0 deletions executor/show_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,16 @@ func TestShowColumnStatsUsage(t *testing.T) {
require.Equal(t, rows[0], []interface{}{"test", "t2", "global", t1.Meta().Columns[0].Name.O, "2021-10-20 09:00:00", "<nil>"})
require.Equal(t, rows[1], []interface{}{"test", "t2", p0.Name.O, t1.Meta().Columns[0].Name.O, "2021-10-20 09:00:00", "<nil>"})
}

func TestShowHistogramsInFlight(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
result := tk.MustQuery("show histograms_in_flight")
rows := result.Rows()
require.Equal(t, len(rows), 1)
require.Equal(t, rows[0][0], "0")
}
6 changes: 6 additions & 0 deletions parser/ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,7 @@ const (
ShowStatsTopN
ShowStatsBuckets
ShowStatsHealthy
ShowHistogramsInFlight
ShowColumnStatsUsage
ShowPlugins
ShowProfile
Expand Down Expand Up @@ -2768,6 +2769,11 @@ func (n *ShowStmt) Restore(ctx *format.RestoreCtx) error {
if err := restoreShowLikeOrWhereOpt(); err != nil {
return err
}
case ShowHistogramsInFlight:
ctx.WriteKeyWord("HISTOGRAMS_IN_FLIGHT")
if err := restoreShowLikeOrWhereOpt(); err != nil {
return err
}
case ShowColumnStatsUsage:
ctx.WriteKeyWord("COLUMN_STATS_USAGE")
if err := restoreShowLikeOrWhereOpt(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ var tokenMap = map[string]int{
"STATS_HISTOGRAMS": statsHistograms,
"STATS_TOPN": statsTopN,
"STATS_META": statsMeta,
"HISTOGRAMS_IN_FLIGHT": histogramsInFlight,
"STATS_PERSISTENT": statsPersistent,
"STATS_SAMPLE_PAGES": statsSamplePages,
"STATS": stats,
Expand Down
Loading