diff --git a/pkg/statistics/handle/autoanalyze/priorityqueue/BUILD.bazel b/pkg/statistics/handle/autoanalyze/priorityqueue/BUILD.bazel index 16ba16edb0787..29a5535235cb4 100644 --- a/pkg/statistics/handle/autoanalyze/priorityqueue/BUILD.bazel +++ b/pkg/statistics/handle/autoanalyze/priorityqueue/BUILD.bazel @@ -46,7 +46,7 @@ go_test( "static_partitioned_table_analysis_job_test.go", ], flaky = True, - shard_count = 28, + shard_count = 29, deps = [ ":priorityqueue", "//pkg/meta/model", diff --git a/pkg/statistics/handle/autoanalyze/priorityqueue/calculatoranalysis/calculator_analysis_test.go b/pkg/statistics/handle/autoanalyze/priorityqueue/calculatoranalysis/calculator_analysis_test.go index 3569a696ad401..68c8439754e88 100644 --- a/pkg/statistics/handle/autoanalyze/priorityqueue/calculatoranalysis/calculator_analysis_test.go +++ b/pkg/statistics/handle/autoanalyze/priorityqueue/calculatoranalysis/calculator_analysis_test.go @@ -272,6 +272,10 @@ func (j *TestJob) GetIndicators() priorityqueue.Indicators { } } +func (j *TestJob) SetIndicators(indicators priorityqueue.Indicators) { + panic("unimplemented") +} + func (j *TestJob) HasNewlyAddedIndex() bool { return false } diff --git a/pkg/statistics/handle/autoanalyze/priorityqueue/dynamic_partitioned_table_analysis_job.go b/pkg/statistics/handle/autoanalyze/priorityqueue/dynamic_partitioned_table_analysis_job.go index 8d8ab745eb3cb..761e5112c13b6 100644 --- a/pkg/statistics/handle/autoanalyze/priorityqueue/dynamic_partitioned_table_analysis_job.go +++ b/pkg/statistics/handle/autoanalyze/priorityqueue/dynamic_partitioned_table_analysis_job.go @@ -110,6 +110,11 @@ func (j *DynamicPartitionedTableAnalysisJob) GetIndicators() Indicators { return j.Indicators } +// SetIndicators sets the indicators of the table. +func (j *DynamicPartitionedTableAnalysisJob) SetIndicators(indicators Indicators) { + j.Indicators = indicators +} + // HasNewlyAddedIndex checks whether the job has newly added index. func (j *DynamicPartitionedTableAnalysisJob) HasNewlyAddedIndex() bool { return len(j.PartitionIndexes) > 0 diff --git a/pkg/statistics/handle/autoanalyze/priorityqueue/job.go b/pkg/statistics/handle/autoanalyze/priorityqueue/job.go index fad719a1a5c07..4aa802837b825 100644 --- a/pkg/statistics/handle/autoanalyze/priorityqueue/job.go +++ b/pkg/statistics/handle/autoanalyze/priorityqueue/job.go @@ -71,6 +71,9 @@ type AnalysisJob interface { // GetIndicators gets the indicators of the job. GetIndicators() Indicators + // SetIndicators sets the indicators of the job. + SetIndicators(indicators Indicators) + // GetTableID gets the table ID of the job. GetTableID() int64 @@ -156,3 +159,9 @@ func isValidToAnalyze( return true, "" } + +// IsDynamicPartitionedTableAnalysisJob checks whether the job is a dynamic partitioned table analysis job. +func IsDynamicPartitionedTableAnalysisJob(job AnalysisJob) bool { + _, ok := job.(*DynamicPartitionedTableAnalysisJob) + return ok +} diff --git a/pkg/statistics/handle/autoanalyze/priorityqueue/job_test.go b/pkg/statistics/handle/autoanalyze/priorityqueue/job_test.go index 9cb2e5a993957..d4c478f494b80 100644 --- a/pkg/statistics/handle/autoanalyze/priorityqueue/job_test.go +++ b/pkg/statistics/handle/autoanalyze/priorityqueue/job_test.go @@ -128,3 +128,34 @@ func TestStringer(t *testing.T) { }) } } + +func TestIsDynamicPartitionedTableAnalysisJob(t *testing.T) { + type args struct { + job priorityqueue.AnalysisJob + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "non-partitioned table", + args: args{ + job: &priorityqueue.NonPartitionedTableAnalysisJob{}, + }, + want: false, + }, + { + name: "dynamic partitioned table", + args: args{ + job: &priorityqueue.DynamicPartitionedTableAnalysisJob{}, + }, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.want, priorityqueue.IsDynamicPartitionedTableAnalysisJob(tt.args.job)) + }) + } +} diff --git a/pkg/statistics/handle/autoanalyze/priorityqueue/non_partitioned_table_analysis_job.go b/pkg/statistics/handle/autoanalyze/priorityqueue/non_partitioned_table_analysis_job.go index 0a4276c16f837..a18adab7c07ff 100644 --- a/pkg/statistics/handle/autoanalyze/priorityqueue/non_partitioned_table_analysis_job.go +++ b/pkg/statistics/handle/autoanalyze/priorityqueue/non_partitioned_table_analysis_job.go @@ -126,6 +126,11 @@ func (j *NonPartitionedTableAnalysisJob) GetIndicators() Indicators { return j.Indicators } +// SetIndicators sets the indicators of the table. +func (j *NonPartitionedTableAnalysisJob) SetIndicators(indicators Indicators) { + j.Indicators = indicators +} + // String implements fmt.Stringer interface. func (j *NonPartitionedTableAnalysisJob) String() string { return fmt.Sprintf( diff --git a/pkg/statistics/handle/autoanalyze/priorityqueue/static_partitioned_table_analysis_job.go b/pkg/statistics/handle/autoanalyze/priorityqueue/static_partitioned_table_analysis_job.go index 2378bc28c061f..348dfb84320de 100644 --- a/pkg/statistics/handle/autoanalyze/priorityqueue/static_partitioned_table_analysis_job.go +++ b/pkg/statistics/handle/autoanalyze/priorityqueue/static_partitioned_table_analysis_job.go @@ -104,6 +104,11 @@ func (j *StaticPartitionedTableAnalysisJob) GetIndicators() Indicators { return j.Indicators } +// SetIndicators implements AnalysisJob. +func (j *StaticPartitionedTableAnalysisJob) SetIndicators(indicators Indicators) { + j.Indicators = indicators +} + // HasNewlyAddedIndex implements AnalysisJob. func (j *StaticPartitionedTableAnalysisJob) HasNewlyAddedIndex() bool { return len(j.Indexes) > 0 diff --git a/pkg/statistics/handle/autoanalyze/refresher/worker_test.go b/pkg/statistics/handle/autoanalyze/refresher/worker_test.go index a11288474470e..eb0b24f08bb69 100644 --- a/pkg/statistics/handle/autoanalyze/refresher/worker_test.go +++ b/pkg/statistics/handle/autoanalyze/refresher/worker_test.go @@ -59,6 +59,9 @@ func (m *mockAnalysisJob) HasNewlyAddedIndex() bool { func (m *mockAnalysisJob) GetIndicators() priorityqueue.Indicators { panic("not implemented") } +func (m *mockAnalysisJob) SetIndicators(indicators priorityqueue.Indicators) { + panic("not implemented") +} func TestWorker(t *testing.T) { _, dom := testkit.CreateMockStoreAndDomain(t)