Skip to content

Commit

Permalink
statistics: correctly handle the ErrPartitionStatsMissing (#47383)
Browse files Browse the repository at this point in the history
close #47384
  • Loading branch information
hawkingrei authored Oct 8, 2023
1 parent 2d1d3fd commit 869c425
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
12 changes: 3 additions & 9 deletions executor/test/analyzetest/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2723,8 +2723,6 @@ PARTITION BY RANGE ( a ) (
tk.MustQuery("show warnings").Sort().Check(testkit.Rows(
"Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p0, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"",
"Warning 1105 Ignore columns and options when analyze partition in dynamic mode",
"Warning 8131 Build global-level stats failed due to missing partition-level stats: table `t` partition `p1`",
"Warning 8131 Build global-level stats failed due to missing partition-level stats: table `t` partition `p1`",
))
tk.MustQuery("select * from t where a > 1 and b > 1 and c > 1 and d > 1")
require.NoError(t, h.LoadNeededHistograms())
Expand All @@ -2736,11 +2734,9 @@ PARTITION BY RANGE ( a ) (
tk.MustExec("analyze table t partition p0")
tk.MustQuery("show warnings").Sort().Check(testkit.Rows(
"Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p0, reason to use this rate is \"use min(1, 110000/9) as the sample-rate=1\"",
"Warning 8131 Build global-level stats failed due to missing partition-level stats: table `t` partition `p1`",
"Warning 8131 Build global-level stats failed due to missing partition-level stats: table `t` partition `p1`",
))
tbl = h.GetTableStats(tableInfo)
require.Equal(t, tbl.Version, lastVersion) // global stats not updated
require.Greater(t, tbl.Version, lastVersion) // global stats updated
}

func TestAnalyzePartitionStaticToDynamic(t *testing.T) {
Expand Down Expand Up @@ -2862,10 +2858,8 @@ PARTITION BY RANGE ( a ) (

// analyze partition with index and with options are allowed under dynamic V1
tk.MustExec("analyze table t partition p0 with 1 topn, 3 buckets")
tk.MustQuery("show warnings").Sort().Check(testkit.Rows(
"Warning 8131 Build global-level stats failed due to missing partition-level stats: table `t` partition `p1`",
"Warning 8131 Build global-level stats failed due to missing partition-level stats: table `t` partition `p1`",
))
rows := tk.MustQuery("show warnings").Rows()
require.Len(t, rows, 0)
tk.MustExec("analyze table t partition p1 with 1 topn, 3 buckets")
tk.MustQuery("show warnings").Sort().Check(testkit.Rows())
tk.MustQuery("select * from t where a > 1 and b > 1 and c > 1 and d > 1")
Expand Down
2 changes: 1 addition & 1 deletion statistics/handle/globalstats/global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func MergePartitionStats2GlobalStats(
var err1 error
partitionStats, err1 = loadTablePartitionStatsFn(tableInfo, &def)
if err1 != nil {
if skipMissingPartitionStats && types.ErrPartitionStatsMissing.Equal(err) {
if skipMissingPartitionStats && types.ErrPartitionStatsMissing.Equal(err1) {
globalStats.MissingPartitionStats = append(globalStats.MissingPartitionStats, fmt.Sprintf("partition `%s`", def.Name.L))
continue
}
Expand Down
2 changes: 0 additions & 2 deletions statistics/handle/handletest/analyze/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ func TestFMSWithAnalyzePartition(t *testing.T) {
tk.MustQuery("show warnings").Sort().Check(testkit.Rows(
"Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p0, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"",
"Warning 1105 Ignore columns and options when analyze partition in dynamic mode",
"Warning 8131 Build global-level stats failed due to missing partition-level stats: table `t` partition `p1`",
"Warning 8131 Build global-level stats failed due to missing partition-level stats: table `t` partition `p1`",
))
tk.MustQuery("select count(*) from mysql.stats_fm_sketch").Check(testkit.Rows("2"))
}
Expand Down

0 comments on commit 869c425

Please sign in to comment.