From 39b2e392632d7b64d959417aac95f56787326316 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Wed, 9 Aug 2023 16:23:39 +0800 Subject: [PATCH 01/14] fixup --- executor/analyze.go | 3 ++- executor/builder.go | 31 ++++++++++++++++++++----------- statistics/analyze_jobs.go | 2 ++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/executor/analyze.go b/executor/analyze.go index 13c9d8dc8a9ec..29029033fc627 100644 --- a/executor/analyze.go +++ b/executor/analyze.go @@ -594,7 +594,8 @@ func finishJobWithLog(sctx sessionctx.Context, job *statistics.AnalyzeJob, analy zap.String("job info", job.JobInfo), zap.Time("start time", job.StartTime), zap.Time("end time", job.EndTime), - zap.String("cost", job.EndTime.Sub(job.StartTime).String())) + zap.String("cost", job.EndTime.Sub(job.StartTime).String()), + zap.String("sample rate reason", job.SampleRateReason)) } } diff --git a/executor/builder.go b/executor/builder.go index 4e199d6a92b57..f08976f561306 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -17,6 +17,7 @@ package executor import ( "bytes" "context" + "fmt" "math" "strconv" "strings" @@ -2706,10 +2707,11 @@ func (b *executorBuilder) buildAnalyzeSamplingPushdown(task plannercore.AnalyzeC modifyCount = int64(val.(int)) }) sampleRate := new(float64) + var sampleRateReason string if opts[ast.AnalyzeOptNumSamples] == 0 { *sampleRate = math.Float64frombits(opts[ast.AnalyzeOptSampleRate]) if *sampleRate < 0 { - *sampleRate = b.getAdjustedSampleRate(task) + *sampleRate, sampleRateReason = b.getAdjustedSampleRate(task) if task.PartitionName != "" { sc.AppendNote(errors.Errorf( "Analyze use auto adjusted sample rate %f for table %s.%s's partition %s", @@ -2718,6 +2720,8 @@ func (b *executorBuilder) buildAnalyzeSamplingPushdown(task plannercore.AnalyzeC task.TableName, task.PartitionName, )) + sc.AppendNote(errors.Errorf("The reason to choose this sample rate for %s.%s's partition %s is: %s", + task.DBName, task.TableName, task.PartitionName, sampleRateReason)) } else { sc.AppendNote(errors.Errorf( "Analyze use auto adjusted sample rate %f for table %s.%s", @@ -2725,13 +2729,16 @@ func (b *executorBuilder) buildAnalyzeSamplingPushdown(task plannercore.AnalyzeC task.DBName, task.TableName, )) + sc.AppendNote(errors.Errorf("The reason to choose this sample rate for table %s.%s is: %s", + task.DBName, task.TableName, sampleRateReason)) } } } job := &statistics.AnalyzeJob{ - DBName: task.DBName, - TableName: task.TableName, - PartitionName: task.PartitionName, + DBName: task.DBName, + TableName: task.TableName, + PartitionName: task.PartitionName, + SampleRateReason: sampleRateReason, } base := baseAnalyzeExec{ @@ -2788,11 +2795,11 @@ func (b *executorBuilder) buildAnalyzeSamplingPushdown(task plannercore.AnalyzeC // If we take n = 1e12, a 300*k sample still gives <= 0.66 bin size error with probability 0.99. // So if we don't consider the top-n values, we can keep the sample size at 300*256. // But we may take some top-n before building the histogram, so we increase the sample a little. -func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsTask) float64 { +func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsTask) (sampleRate float64, reason string) { statsHandle := domain.GetDomain(b.ctx).StatsHandle() defaultRate := 0.001 if statsHandle == nil { - return defaultRate + return defaultRate, fmt.Sprintf("statsHandler is nil, use the default-rate=%v", defaultRate) } var statsTbl *statistics.Table tid := task.TableID.GetStatisticsID() @@ -2804,11 +2811,11 @@ func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsT approxiCount, hasPD := b.getApproximateTableCountFromStorage(tid, task) // If there's no stats meta and no pd, return the default rate. if statsTbl == nil && !hasPD { - return defaultRate + return defaultRate, fmt.Sprintf("statsTbl is nil and no pd info, use the default-rate=%v", defaultRate) } // If the count in stats_meta is still 0 and there's no information from pd side, we scan all rows. if statsTbl.RealtimeCount == 0 && !hasPD { - return 1 + return 1, fmt.Sprintf("statsTbl.RealtimeCount is 0 and no pd info, use sample-rate=1") } // we have issue https://github.com/pingcap/tidb/issues/29216. // To do a workaround for this issue, we check the approxiCount from the pd side to do a comparison. @@ -2817,15 +2824,17 @@ func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsT if float64(statsTbl.RealtimeCount*5) < approxiCount { // Confirmed by TiKV side, the experience error rate of the approximate count is about 20%. // So we increase the number to 150000 to reduce this error rate. - return math.Min(1, 150000/approxiCount) + sampleRate = math.Min(1, 150000/approxiCount) + return sampleRate, fmt.Sprintf("statsTbl.RealtimeCount is too small, use min(1, 15000/%v) as the sample-rate=%v", approxiCount, sampleRate) } // If we don't go into the above if branch and we still detect the count is zero. Return 1 to prevent the dividing zero. if statsTbl.RealtimeCount == 0 { - return 1 + return 1, fmt.Sprintf("statsTbl.RealtimeCount is 0, use sample-rate=1") } // We are expected to scan about 100000 rows or so. // Since there's tiny error rate around the count from the stats meta, we use 110000 to get a little big result - return math.Min(1, config.DefRowsForSampleRate/float64(statsTbl.RealtimeCount)) + sampleRate = math.Min(1, config.DefRowsForSampleRate/float64(statsTbl.RealtimeCount)) + return sampleRate, fmt.Sprintf("use min(1, %v/%v) as the sample-rate=%v", config.DefRowsForSampleRate, statsTbl.RealtimeCount, sampleRate) } func (b *executorBuilder) getApproximateTableCountFromStorage(tid int64, task plannercore.AnalyzeColumnsTask) (float64, bool) { diff --git a/statistics/analyze_jobs.go b/statistics/analyze_jobs.go index e93d3c427192a..08e06e2ecbea4 100644 --- a/statistics/analyze_jobs.go +++ b/statistics/analyze_jobs.go @@ -29,6 +29,8 @@ type AnalyzeJob struct { PartitionName string JobInfo string Progress AnalyzeProgress + + SampleRateReason string // why this sample-rate is chosen } // AnalyzeProgress represents the process of one analyze job. From 6b4d9c3846a2938f329d293f7b9109cdb80c1370 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Wed, 9 Aug 2023 16:35:08 +0800 Subject: [PATCH 02/14] fixup --- executor/builder.go | 10 ++--- executor/test/analyzetest/analyze_test.go | 50 ++++++++++++++++------- statistics/analyze_jobs.go | 2 +- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/executor/builder.go b/executor/builder.go index f08976f561306..301ba941ab3d8 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -2714,23 +2714,21 @@ func (b *executorBuilder) buildAnalyzeSamplingPushdown(task plannercore.AnalyzeC *sampleRate, sampleRateReason = b.getAdjustedSampleRate(task) if task.PartitionName != "" { sc.AppendNote(errors.Errorf( - "Analyze use auto adjusted sample rate %f for table %s.%s's partition %s", + `Analyze use auto adjusted sample rate %f for table %s.%s's partition %s, reason to use this rate is "%s"`, *sampleRate, task.DBName, task.TableName, task.PartitionName, + sampleRateReason, )) - sc.AppendNote(errors.Errorf("The reason to choose this sample rate for %s.%s's partition %s is: %s", - task.DBName, task.TableName, task.PartitionName, sampleRateReason)) } else { sc.AppendNote(errors.Errorf( - "Analyze use auto adjusted sample rate %f for table %s.%s", + `Analyze use auto adjusted sample rate %f for table %s.%s, reason to use this rate is "%s"`, *sampleRate, task.DBName, task.TableName, + sampleRateReason, )) - sc.AppendNote(errors.Errorf("The reason to choose this sample rate for table %s.%s is: %s", - task.DBName, task.TableName, sampleRateReason)) } } } diff --git a/executor/test/analyzetest/analyze_test.go b/executor/test/analyzetest/analyze_test.go index 25934493e075a..d134db5f07229 100644 --- a/executor/test/analyzetest/analyze_test.go +++ b/executor/test/analyzetest/analyze_test.go @@ -669,14 +669,14 @@ func TestAdjustSampleRateNote(t *testing.T) { result := tk.MustQuery("show stats_meta where table_name = 't'") require.Equal(t, "220000", result.Rows()[0][5]) tk.MustExec("analyze table t") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1105 Analyze use auto adjusted sample rate 0.500000 for table test.t")) + tk.MustQuery("show warnings").Check(testkit.Rows("Note 1105 Analyze use auto adjusted sample rate 0.500000 for table test.t, reason to use this rate is \"use min(1, 110000/220000) as the sample-rate=0.5\"")) tk.MustExec("insert into t values(1),(1),(1)") require.NoError(t, statsHandle.DumpStatsDeltaToKV(handle.DumpAll)) require.NoError(t, statsHandle.Update(is)) result = tk.MustQuery("show stats_meta where table_name = 't'") require.Equal(t, "3", result.Rows()[0][5]) tk.MustExec("analyze table t") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t")) + tk.MustQuery("show warnings").Check(testkit.Rows("Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/3) as the sample-rate=1\"")) } func TestFastAnalyze4GlobalStats(t *testing.T) { @@ -925,7 +925,7 @@ func TestSmallTableAnalyzeV2(t *testing.T) { tk.MustExec("create table small_table_inject_pd(a int)") tk.MustExec("insert into small_table_inject_pd values(1), (2), (3), (4), (5)") tk.MustExec("analyze table small_table_inject_pd") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.small_table_inject_pd")) + tk.MustQuery("show warnings").Check(testkit.Rows("Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.small_table_inject_pd, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"")) tk.MustExec(` create table small_table_inject_pd_with_partition( a int @@ -937,9 +937,9 @@ create table small_table_inject_pd_with_partition( tk.MustExec("insert into small_table_inject_pd_with_partition values(1), (6), (11)") tk.MustExec("analyze table small_table_inject_pd_with_partition") tk.MustQuery("show warnings").Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.small_table_inject_pd_with_partition's partition p0", - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.small_table_inject_pd_with_partition's partition p1", - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.small_table_inject_pd_with_partition's partition p2", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.small_table_inject_pd_with_partition's partition p0, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.small_table_inject_pd_with_partition's partition p1, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.small_table_inject_pd_with_partition's partition p2, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", )) rows := [][]interface{}{ {"global", "a"}, @@ -1421,7 +1421,7 @@ func TestAnalyzeColumnsWithPrimaryKey(t *testing.T) { case model.ColumnList: tk.MustExec("analyze table t columns a with 2 topn, 2 buckets") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 1105 Columns c are missing in ANALYZE but their stats are needed for calculating stats for indexes/primary key/extended stats", )) case model.PredicateColumns: @@ -2096,6 +2096,26 @@ func TestAnalyzeColumnsAfterAnalyzeAll(t *testing.T) { } } +func TestAnalyzeSampleRateReason(t *testing.T) { + store, dom := testkit.CreateMockStoreAndDomain(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (a int, b int)") + require.NoError(t, dom.StatsHandle().DumpStatsDeltaToKV(handle.DumpAll)) + + tk.MustExec(`analyze table t`) + tk.MustQuery(`show warnings`).Sort().Check(testkit.Rows( + `Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "use min(1, 110000/10000) as the sample-rate=1"`)) + + tk.MustExec(`insert into t values (1, 1), (2, 2), (3, 3)`) + require.NoError(t, dom.StatsHandle().DumpStatsDeltaToKV(handle.DumpAll)) + tk.MustExec(`analyze table t`) + tk.MustQuery(`show warnings`).Sort().Check(testkit.Rows( + `Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "statsTbl.RealtimeCount is 0, use sample-rate=1"`)) +} + func TestAnalyzeColumnsErrorAndWarning(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) @@ -2120,7 +2140,7 @@ func TestAnalyzeColumnsErrorAndWarning(t *testing.T) { // If no predicate column is collected, analyze predicate columns gives a warning and falls back to analyze all columns. tk.MustExec("analyze table t predicate columns") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t", + `Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "use min(1, 110000/10000) as the sample-rate=1"`, "Warning 1105 No predicate column has been collected yet for table test.t so all columns are analyzed", )) rows := tk.MustQuery("show column_stats_usage where db_name = 'test' and table_name = 't' and last_analyzed_at is not null").Rows() @@ -2145,7 +2165,7 @@ func TestAnalyzeColumnsErrorAndWarning(t *testing.T) { tk.MustExec("analyze table t predicate columns") } tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t", + `Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "statsTbl.RealtimeCount is 0, use sample-rate=1"`, "Warning 1105 Table test.t has version 1 statistics so all the columns must be analyzed to overwrite the current statistics", )) }(val) @@ -2731,7 +2751,7 @@ PARTITION BY RANGE ( a ) ( // analyze partition with options under dynamic mode tk.MustExec("analyze table t partition p0 columns a,b,c with 1 topn, 3 buckets") 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", + "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`", @@ -2745,7 +2765,7 @@ 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", + "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`", )) @@ -2801,7 +2821,7 @@ PARTITION BY RANGE ( a ) ( tk.MustExec("set @@session.tidb_partition_prune_mode = 'dynamic'") tk.MustExec("analyze table t partition p1 columns a,b,d with 1 topn, 3 buckets") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 8244 Build global-level stats failed due to missing partition-level column stats: table `t` partition `p0` column `d`, please run analyze table to refresh columns of all partitions", )) @@ -2810,7 +2830,7 @@ PARTITION BY RANGE ( a ) ( tk.MustExec("set global tidb_persist_analyze_options = true") tk.MustExec("analyze table t partition p1 columns a,b,d with 1 topn, 3 buckets") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1, reason to use this rate is \"use min(1, 110000/5) as the sample-rate=1\"", "Warning 1105 Ignore columns and options when analyze partition in dynamic mode", "Warning 8244 Build global-level stats failed due to missing partition-level column stats: table `t` partition `p0` column `d`, please run analyze table to refresh columns of all partitions", )) @@ -2819,7 +2839,7 @@ PARTITION BY RANGE ( a ) ( tk.MustExec("insert into mysql.analyze_options values (?,?,?,?,?,?,?)", pi.Definitions[1].ID, 0, 0, 1, 1, "DEFAULT", "") tk.MustExec("analyze table t partition p1 columns a,b,d with 1 topn, 3 buckets") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1, reason to use this rate is \"use min(1, 110000/5) as the sample-rate=1\"", "Warning 1105 Ignore columns and options when analyze partition in dynamic mode", "Warning 8244 Build global-level stats failed due to missing partition-level column stats: table `t` partition `p0` column `d`, please run analyze table to refresh columns of all partitions", )) @@ -3224,7 +3244,7 @@ func TestAnalyzeColumnsSkipMVIndexJsonCol(t *testing.T) { tk.MustExec("analyze table t columns a") tk.MustQuery("show warnings").Sort().Check(testkit.Rows(""+ - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 1105 Columns b are missing in ANALYZE but their stats are needed for calculating stats for indexes/primary key/extended stats", "Warning 1105 analyzing multi-valued indexes is not supported, skip idx_c")) tk.MustQuery("select job_info from mysql.analyze_jobs where table_schema = 'test' and table_name = 't'").Check(testkit.Rows( diff --git a/statistics/analyze_jobs.go b/statistics/analyze_jobs.go index 08e06e2ecbea4..cbbbf48b0ecb0 100644 --- a/statistics/analyze_jobs.go +++ b/statistics/analyze_jobs.go @@ -28,9 +28,9 @@ type AnalyzeJob struct { TableName string PartitionName string JobInfo string - Progress AnalyzeProgress SampleRateReason string // why this sample-rate is chosen + Progress AnalyzeProgress } // AnalyzeProgress represents the process of one analyze job. From c2971af7bf05629015d55443acab8ee0c417b8e4 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Wed, 9 Aug 2023 17:10:48 +0800 Subject: [PATCH 03/14] fixup --- executor/test/analyzetest/analyze_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/executor/test/analyzetest/analyze_test.go b/executor/test/analyzetest/analyze_test.go index d134db5f07229..ec9c89f95f9c1 100644 --- a/executor/test/analyzetest/analyze_test.go +++ b/executor/test/analyzetest/analyze_test.go @@ -1489,7 +1489,7 @@ func TestAnalyzeColumnsWithIndex(t *testing.T) { case model.ColumnList: tk.MustExec("analyze table t columns c with 2 topn, 2 buckets") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 1105 Columns b,d are missing in ANALYZE but their stats are needed for calculating stats for indexes/primary key/extended stats", )) case model.PredicateColumns: @@ -1566,7 +1566,7 @@ func TestAnalyzeColumnsWithClusteredIndex(t *testing.T) { case model.ColumnList: tk.MustExec("analyze table t columns c with 2 topn, 2 buckets") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 1105 Columns b,d are missing in ANALYZE but their stats are needed for calculating stats for indexes/primary key/extended stats", )) case model.PredicateColumns: @@ -1647,8 +1647,8 @@ func TestAnalyzeColumnsWithDynamicPartitionTable(t *testing.T) { case model.ColumnList: tk.MustExec("analyze table t columns a with 2 topn, 2 buckets") 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", - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1", + "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\"", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 1105 Columns c are missing in ANALYZE but their stats are needed for calculating stats for indexes/primary key/extended stats", )) case model.PredicateColumns: @@ -1799,8 +1799,8 @@ func TestAnalyzeColumnsWithStaticPartitionTable(t *testing.T) { case model.ColumnList: tk.MustExec("analyze table t columns a with 2 topn, 2 buckets") 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", - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1", + "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\"", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 1105 Columns c are missing in ANALYZE but their stats are needed for calculating stats for indexes/primary key/extended stats", )) case model.PredicateColumns: @@ -1904,7 +1904,7 @@ func TestAnalyzeColumnsWithExtendedStats(t *testing.T) { case model.ColumnList: tk.MustExec("analyze table t columns b with 2 topn, 2 buckets") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 1105 Columns c are missing in ANALYZE but their stats are needed for calculating stats for indexes/primary key/extended stats", )) case model.PredicateColumns: @@ -1974,7 +1974,7 @@ func TestAnalyzeColumnsWithVirtualColumnIndex(t *testing.T) { case model.ColumnList: tk.MustExec("analyze table t columns b with 2 topn, 2 buckets") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 1105 Columns c are missing in ANALYZE but their stats are needed for calculating stats for indexes/primary key/extended stats", )) case model.PredicateColumns: From 474e201759a35e9b8780c29a8b1d878b8524b00f Mon Sep 17 00:00:00 2001 From: qw4990 Date: Wed, 9 Aug 2023 17:11:31 +0800 Subject: [PATCH 04/14] fixup --- executor/analyze_test.go | 4 ++-- executor/infoschema_reader_test.go | 2 +- planner/core/indexmerge_path_test.go | 4 ++-- planner/core/integration_test.go | 2 +- statistics/handle/handletest/analyze/analyze_test.go | 2 +- statistics/integration_test.go | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/executor/analyze_test.go b/executor/analyze_test.go index f981c48465296..5bedabbc5d99c 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -431,8 +431,8 @@ func TestMergeGlobalStatsWithUnAnalyzedPartition(t *testing.T) { tk.MustExec("analyze table t partition p2 index idxc;") tk.MustQuery("show warnings").Check(testkit.Rows( "Warning 1105 The version 2 would collect all statistics not only the selected indexes", - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p2")) + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p2, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"")) tk.MustExec("analyze table t partition p0;") tk.MustQuery("show warnings").Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p0")) + "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\"")) } diff --git a/executor/infoschema_reader_test.go b/executor/infoschema_reader_test.go index 138f2d84071c2..1b8e044971334 100644 --- a/executor/infoschema_reader_test.go +++ b/executor/infoschema_reader_test.go @@ -594,7 +594,7 @@ func TestForAnalyzeStatus(t *testing.T) { tk.MustExec("create table t1 (a int, b int, index idx(a))") tk.MustExec("insert into t1 values (1,2),(3,4)") tk.MustExec("analyze table t1") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t1")) // 1 note. + tk.MustQuery("show warnings").Check(testkit.Rows("Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t1, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"")) // 1 note. require.NoError(t, dom.StatsHandle().LoadNeededHistograms()) tk.MustExec("CREATE ROLE r_t1 ;") tk.MustExec("GRANT ALL PRIVILEGES ON test.t1 TO r_t1;") diff --git a/planner/core/indexmerge_path_test.go b/planner/core/indexmerge_path_test.go index e676b82d6f1a1..433e1c6d28da5 100644 --- a/planner/core/indexmerge_path_test.go +++ b/planner/core/indexmerge_path_test.go @@ -39,12 +39,12 @@ index idx2(a, b, (cast(j->'$.str' as char(10) array)), c))`) tk.MustExec("set tidb_analyze_version=2") tk.MustExec("analyze table t") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 1105 analyzing multi-valued indexes is not supported, skip idx", "Warning 1105 analyzing multi-valued indexes is not supported, skip idx2")) tk.MustExec("analyze table t index idx") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", "Warning 1105 The version 2 would collect all statistics not only the selected indexes", "Warning 1105 analyzing multi-valued indexes is not supported, skip idx", "Warning 1105 analyzing multi-valued indexes is not supported, skip idx2")) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index f74ec6da97c11..aad0a5b06b09c 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -2953,7 +2953,7 @@ func TestIncrementalAnalyzeStatsVer2(t *testing.T) { require.Len(t, warns, 3) require.EqualError(t, warns[0].Err, "The version 2 would collect all statistics not only the selected indexes") require.EqualError(t, warns[1].Err, "The version 2 stats would ignore the INCREMENTAL keyword and do full sampling") - require.EqualError(t, warns[2].Err, "Analyze use auto adjusted sample rate 1.000000 for table test.t") + require.EqualError(t, warns[2].Err, "Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"") rows = tk.MustQuery(fmt.Sprintf("select distinct_count from mysql.stats_histograms where table_id = %d and is_index = 1", tblID)).Rows() require.Len(t, rows, 1) require.Equal(t, "6", rows[0][0]) diff --git a/statistics/handle/handletest/analyze/analyze_test.go b/statistics/handle/handletest/analyze/analyze_test.go index b785fb0b2c648..6c42871bc8a62 100644 --- a/statistics/handle/handletest/analyze/analyze_test.go +++ b/statistics/handle/handletest/analyze/analyze_test.go @@ -242,7 +242,7 @@ func TestFMSWithAnalyzePartition(t *testing.T) { 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").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p0", + "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`", diff --git a/statistics/integration_test.go b/statistics/integration_test.go index ea01cee24fccc..d6140d437e59e 100644 --- a/statistics/integration_test.go +++ b/statistics/integration_test.go @@ -169,7 +169,7 @@ func TestChangeVerTo2BehaviorWithPersistedOptions(t *testing.T) { tk.MustExec("analyze table t index idx") tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 The analyze version from the session is not compatible with the existing statistics of the table. Use the existing version instead", "Warning 1105 The version 2 would collect all statistics not only the selected indexes", - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t")) // since fallback to ver2 path, should do samplerate adjustment + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"")) // since fallback to ver2 path, should do samplerate adjustment require.NoError(t, h.Update(is)) statsTblT = h.GetTableStats(tblT.Meta()) for _, idx := range statsTblT.Indices { @@ -178,7 +178,7 @@ func TestChangeVerTo2BehaviorWithPersistedOptions(t *testing.T) { tk.MustExec("analyze table t index") tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 The analyze version from the session is not compatible with the existing statistics of the table. Use the existing version instead", "Warning 1105 The version 2 would collect all statistics not only the selected indexes", - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t")) + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"")) require.NoError(t, h.Update(is)) statsTblT = h.GetTableStats(tblT.Meta()) for _, idx := range statsTblT.Indices { From 8033246a650dc2a69654049b8ed5ae6c3b777b9d Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Wed, 9 Aug 2023 17:26:38 +0800 Subject: [PATCH 05/14] Update executor/builder.go Co-authored-by: Yiding Cui --- executor/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/builder.go b/executor/builder.go index 301ba941ab3d8..44d674d435d97 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -2827,7 +2827,7 @@ func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsT } // If we don't go into the above if branch and we still detect the count is zero. Return 1 to prevent the dividing zero. if statsTbl.RealtimeCount == 0 { - return 1, fmt.Sprintf("statsTbl.RealtimeCount is 0, use sample-rate=1") + return 1, fmt.Sprintf("TiDB assumes that the table is empty, use sample-rate=1") } // We are expected to scan about 100000 rows or so. // Since there's tiny error rate around the count from the stats meta, we use 110000 to get a little big result From ab19b3e5128c9aebc1ae5e2e7ca501e3f91cb8d7 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Wed, 9 Aug 2023 17:26:45 +0800 Subject: [PATCH 06/14] Update executor/builder.go Co-authored-by: Yiding Cui --- executor/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/builder.go b/executor/builder.go index 44d674d435d97..db55f38910948 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -2823,7 +2823,7 @@ func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsT // Confirmed by TiKV side, the experience error rate of the approximate count is about 20%. // So we increase the number to 150000 to reduce this error rate. sampleRate = math.Min(1, 150000/approxiCount) - return sampleRate, fmt.Sprintf("statsTbl.RealtimeCount is too small, use min(1, 15000/%v) as the sample-rate=%v", approxiCount, sampleRate) + return sampleRate, fmt.Sprintf("Row count in stats_meta is much smaller compared with the row count got by PD, use min(1, 15000/%v) as the sample-rate=%v", approxiCount, sampleRate) } // If we don't go into the above if branch and we still detect the count is zero. Return 1 to prevent the dividing zero. if statsTbl.RealtimeCount == 0 { From d2425a4c98194e503cf08b70ab6ec50f539e37f4 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Wed, 9 Aug 2023 17:27:00 +0800 Subject: [PATCH 07/14] Update executor/builder.go Co-authored-by: Yiding Cui --- executor/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/builder.go b/executor/builder.go index db55f38910948..ee6ac068adf1d 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -2813,7 +2813,7 @@ func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsT } // If the count in stats_meta is still 0 and there's no information from pd side, we scan all rows. if statsTbl.RealtimeCount == 0 && !hasPD { - return 1, fmt.Sprintf("statsTbl.RealtimeCount is 0 and no pd info, use sample-rate=1") + return 1, fmt.Sprintf("Tidb assumes that the table is empty, use sample-rate=1") } // we have issue https://github.com/pingcap/tidb/issues/29216. // To do a workaround for this issue, we check the approxiCount from the pd side to do a comparison. From ec864770042d074b77187d7646a89e2be3b04d33 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Wed, 9 Aug 2023 17:27:08 +0800 Subject: [PATCH 08/14] Update executor/builder.go Co-authored-by: Yiding Cui --- executor/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/builder.go b/executor/builder.go index ee6ac068adf1d..60e127a240fda 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -2809,7 +2809,7 @@ func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsT approxiCount, hasPD := b.getApproximateTableCountFromStorage(tid, task) // If there's no stats meta and no pd, return the default rate. if statsTbl == nil && !hasPD { - return defaultRate, fmt.Sprintf("statsTbl is nil and no pd info, use the default-rate=%v", defaultRate) + return defaultRate, fmt.Sprintf("TiDB cannot get the row count of the table, use the default-rate=%v", defaultRate) } // If the count in stats_meta is still 0 and there's no information from pd side, we scan all rows. if statsTbl.RealtimeCount == 0 && !hasPD { From 03567d73f821c07211e0b02a907454c5a8001850 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Thu, 10 Aug 2023 13:33:21 +0800 Subject: [PATCH 09/14] fixup --- executor/builder.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/builder.go b/executor/builder.go index 60e127a240fda..a394d95a23f57 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -2813,7 +2813,7 @@ func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsT } // If the count in stats_meta is still 0 and there's no information from pd side, we scan all rows. if statsTbl.RealtimeCount == 0 && !hasPD { - return 1, fmt.Sprintf("Tidb assumes that the table is empty, use sample-rate=1") + return 1, "TiDB assumes that the table is empty and cannot get row count from PD, use sample-rate=1" } // we have issue https://github.com/pingcap/tidb/issues/29216. // To do a workaround for this issue, we check the approxiCount from the pd side to do a comparison. @@ -2827,7 +2827,7 @@ func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsT } // If we don't go into the above if branch and we still detect the count is zero. Return 1 to prevent the dividing zero. if statsTbl.RealtimeCount == 0 { - return 1, fmt.Sprintf("TiDB assumes that the table is empty, use sample-rate=1") + return 1, "TiDB assumes that the table is empty, use sample-rate=1" } // We are expected to scan about 100000 rows or so. // Since there's tiny error rate around the count from the stats meta, we use 110000 to get a little big result From aef79f3221655d611fcd730b2fe9b89993b40de7 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Thu, 10 Aug 2023 13:53:48 +0800 Subject: [PATCH 10/14] fixup --- statistics/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/statistics/integration_test.go b/statistics/integration_test.go index d6140d437e59e..0fcd201cb1a31 100644 --- a/statistics/integration_test.go +++ b/statistics/integration_test.go @@ -169,7 +169,7 @@ func TestChangeVerTo2BehaviorWithPersistedOptions(t *testing.T) { tk.MustExec("analyze table t index idx") tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 The analyze version from the session is not compatible with the existing statistics of the table. Use the existing version instead", "Warning 1105 The version 2 would collect all statistics not only the selected indexes", - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"")) // since fallback to ver2 path, should do samplerate adjustment + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/3) as the sample-rate=1\"")) // since fallback to ver2 path, should do samplerate adjustment require.NoError(t, h.Update(is)) statsTblT = h.GetTableStats(tblT.Meta()) for _, idx := range statsTblT.Indices { @@ -178,7 +178,7 @@ func TestChangeVerTo2BehaviorWithPersistedOptions(t *testing.T) { tk.MustExec("analyze table t index") tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 The analyze version from the session is not compatible with the existing statistics of the table. Use the existing version instead", "Warning 1105 The version 2 would collect all statistics not only the selected indexes", - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"")) + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/3) as the sample-rate=1\"")) require.NoError(t, h.Update(is)) statsTblT = h.GetTableStats(tblT.Meta()) for _, idx := range statsTblT.Indices { From ae77c752a57930980414203ca71c103fa13d2173 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Thu, 10 Aug 2023 14:28:29 +0800 Subject: [PATCH 11/14] fixup --- planner/core/indexmerge_path_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/indexmerge_path_test.go b/planner/core/indexmerge_path_test.go index 433e1c6d28da5..66d1a0bd9baec 100644 --- a/planner/core/indexmerge_path_test.go +++ b/planner/core/indexmerge_path_test.go @@ -44,7 +44,7 @@ index idx2(a, b, (cast(j->'$.str' as char(10) array)), c))`) "Warning 1105 analyzing multi-valued indexes is not supported, skip idx2")) tk.MustExec("analyze table t index idx") tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", + "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"TiDB assumes that the table is empty, use sample-rate=1\"", "Warning 1105 The version 2 would collect all statistics not only the selected indexes", "Warning 1105 analyzing multi-valued indexes is not supported, skip idx", "Warning 1105 analyzing multi-valued indexes is not supported, skip idx2")) From 2fac270213f78fa884abc97b618b07b39ad5126c Mon Sep 17 00:00:00 2001 From: qw4990 Date: Thu, 10 Aug 2023 15:14:01 +0800 Subject: [PATCH 12/14] fixup --- planner/core/integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index aad0a5b06b09c..dda7061022c49 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -2953,7 +2953,7 @@ func TestIncrementalAnalyzeStatsVer2(t *testing.T) { require.Len(t, warns, 3) require.EqualError(t, warns[0].Err, "The version 2 would collect all statistics not only the selected indexes") require.EqualError(t, warns[1].Err, "The version 2 stats would ignore the INCREMENTAL keyword and do full sampling") - require.EqualError(t, warns[2].Err, "Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"") + require.EqualError(t, warns[2].Err, "Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/3) as the sample-rate=1\"") rows = tk.MustQuery(fmt.Sprintf("select distinct_count from mysql.stats_histograms where table_id = %d and is_index = 1", tblID)).Rows() require.Len(t, rows, 1) require.Equal(t, "6", rows[0][0]) From 51ce0a916260c1847b4a27e2111518789d9b8d33 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Thu, 10 Aug 2023 16:24:46 +0800 Subject: [PATCH 13/14] fixup --- executor/analyze_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/analyze_test.go b/executor/analyze_test.go index 5bedabbc5d99c..74b0fb94b1904 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -434,5 +434,5 @@ func TestMergeGlobalStatsWithUnAnalyzedPartition(t *testing.T) { "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p2, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"")) tk.MustExec("analyze table t partition p0;") tk.MustQuery("show warnings").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\"")) + "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/2) as the sample-rate=1\"")) } From a2f7b5979b86be5b7870bde7001656d2f7f6dadf Mon Sep 17 00:00:00 2001 From: qw4990 Date: Thu, 10 Aug 2023 16:27:59 +0800 Subject: [PATCH 14/14] fixup --- executor/test/analyzetest/analyze_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/test/analyzetest/analyze_test.go b/executor/test/analyzetest/analyze_test.go index ec9c89f95f9c1..11e168105fab9 100644 --- a/executor/test/analyzetest/analyze_test.go +++ b/executor/test/analyzetest/analyze_test.go @@ -2113,7 +2113,7 @@ func TestAnalyzeSampleRateReason(t *testing.T) { require.NoError(t, dom.StatsHandle().DumpStatsDeltaToKV(handle.DumpAll)) tk.MustExec(`analyze table t`) tk.MustQuery(`show warnings`).Sort().Check(testkit.Rows( - `Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "statsTbl.RealtimeCount is 0, use sample-rate=1"`)) + `Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "TiDB assumes that the table is empty, use sample-rate=1"`)) } func TestAnalyzeColumnsErrorAndWarning(t *testing.T) { @@ -2165,7 +2165,7 @@ func TestAnalyzeColumnsErrorAndWarning(t *testing.T) { tk.MustExec("analyze table t predicate columns") } tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - `Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "statsTbl.RealtimeCount is 0, use sample-rate=1"`, + `Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "TiDB assumes that the table is empty, use sample-rate=1"`, "Warning 1105 Table test.t has version 1 statistics so all the columns must be analyzed to overwrite the current statistics", )) }(val)