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

domain: let plan replayer dump support recording stats mem status #40334

Merged
merged 6 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions domain/plan_replayer_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ var (
| |-stats1.json
| |-stats2.json
| |-....
|-statsMem
| |-stats1.txt
| |-stats2.txt
| |-....
|-config.toml
|-table_tiflash_replica.txt
|-variables.toml
Expand Down Expand Up @@ -282,6 +286,10 @@ func DumpPlanReplayerInfo(ctx context.Context, sctx sessionctx.Context,
}
}

if err = dumpStatsMemStatus(zw, pairs, do); err != nil {
return err
}

// Dump variables
if err = dumpVariables(sctx, sessionVars, zw); err != nil {
return err
Expand Down Expand Up @@ -424,6 +432,37 @@ func dumpSchemaMeta(zw *zip.Writer, tables map[tableNamePair]struct{}) error {
return nil
}

func dumpStatsMemStatus(zw *zip.Writer, pairs map[tableNamePair]struct{}, do *Domain) error {
statsHandle := do.StatsHandle()
is := do.InfoSchema()
for pair := range pairs {
if pair.IsView {
continue
}
tbl, err := is.TableByName(model.NewCIStr(pair.DBName), model.NewCIStr(pair.TableName))
if err != nil {
return err
}
tblStats := statsHandle.GetTableStats(tbl.Meta())
if tblStats == nil {
continue
}
statsMemFw, err := zw.Create(fmt.Sprintf("statsMem/%v.%v.txt", pair.DBName, pair.TableName))
if err != nil {
return errors.AddStack(err)
}
fmt.Fprintf(statsMemFw, "[INDEX]\n")
for _, indice := range tblStats.Indices {
fmt.Fprintf(statsMemFw, "%s\n", fmt.Sprintf("%s=%s", indice.Info.Name.String(), indice.StatusToString()))
}
fmt.Fprintf(statsMemFw, "[COLUMN]\n")
for _, col := range tblStats.Columns {
fmt.Fprintf(statsMemFw, "%s\n", fmt.Sprintf("%s=%s", col.Info.Name.String(), col.StatusToString()))
}
}
return nil
}

func dumpStats(zw *zip.Writer, pairs map[tableNamePair]struct{}, do *Domain) error {
for pair := range pairs {
if pair.IsView {
Expand Down
1 change: 1 addition & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func checkFileName(s string) bool {
"global_bindings.sql",
"sql/sql0.sql",
"explain/sql0.txt",
"statsMem/test.t_dump_single.txt",
"sql_meta.toml",
}
for _, f := range files {
Expand Down