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

statistics: add test for analyze single partition #23167

Merged
merged 8 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
resolve comments
  • Loading branch information
rebelice committed Mar 8, 2021
commit dbd522c9951329feae755e34d3d9fe19b97d2d00
2 changes: 1 addition & 1 deletion errno/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrInvalidTableSample: mysql.Message("Invalid TABLESAMPLE: %s", nil),

ErrJSONObjectKeyTooLong: mysql.Message("TiDB does not yet support JSON objects with the key length >= 65536", nil),
ErrBuildGlobalLevelStatsFailed: mysql.Message("Build global-level stats failed due to missing partition-level stats", nil),
ErrBuildGlobalLevelStatsFailed: mysql.Message("Build table: %s global-level stats failed due to missing partition-level stats", nil),

ErrInvalidPlacementSpec: mysql.Message("Invalid placement policy '%s': %s", nil),
ErrPlacementPolicyCheck: mysql.Message("Placement policy didn't meet the constraint, reason: %s", nil),
Expand Down
14 changes: 13 additions & 1 deletion statistics/handle/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,19 @@ func (h *Handle) MergePartitionStats2GlobalStats(sc sessionctx.Context, opts map
}
// if the err == nil && partitionStats == nil, it means we lack the partition-level stats which the physicalID is equal to partitionID.
if partitionStats == nil {
err = types.ErrBuildGlobalLevelStatsFailed
var errMsg string
if isIndex == 0 {
errMsg = fmt.Sprintf("`%s`", tableInfo.Name.L)
} else {
indexName := ""
for _, idx := range tableInfo.Indices {
if idx.ID == idxID {
indexName = idx.Name.L
}
}
errMsg = fmt.Sprintf("`%s` index: `%s`", tableInfo.Name.L, indexName)
}
err = types.ErrBuildGlobalLevelStatsFailed.GenWithStackByArgs(errMsg)
return
}
statistics.CheckAnalyzeVerOnTable(partitionStats, &statsVer)
Expand Down
7 changes: 4 additions & 3 deletions statistics/handle/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func cleanEnv(c *C, store kv.Storage, do *domain.Domain) {
tk.MustExec("delete from mysql.stats_histograms")
tk.MustExec("delete from mysql.stats_buckets")
tk.MustExec("delete from mysql.stats_extended")
tk.MustExec("delete from mysql.stats_fm_sketch")
tk.MustExec("delete from mysql.schema_index_usage")
do.StatsHandle().Clear()
}
Expand Down Expand Up @@ -1431,9 +1432,9 @@ func (s *testStatsSuite) TestFMSWithAnalyzePartition(c *C) {
tk.MustExec(`insert into t values (1), (2), (3), (10), (11)`)
tk.MustQuery("select count(*) from mysql.stats_fm_sketch").Check(testkit.Rows("0"))
tk.MustExec("analyze table t partition p0 with 1 topn, 2 buckets")
tk.MustQuery("show warnings").Check(testkit.Rows(
"Warning 8131 Build global-level stats failed due to missing partition-level stats",
"Warning 8131 Build global-level stats failed due to missing partition-level stats",
tk.MustQuery("show warnings").Sort().Check(testkit.Rows(
"Warning 8131 Build table: `t` global-level stats failed due to missing partition-level stats",
"Warning 8131 Build table: `t` index: `a` global-level stats failed due to missing partition-level stats",
))
tk.MustQuery("select count(*) from mysql.stats_fm_sketch").Check(testkit.Rows("1"))
}
Expand Down