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 the SetIndicators API #56248

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pkg/statistics/handle/autoanalyze/priorityqueue/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
31 changes: 31 additions & 0 deletions pkg/statistics/handle/autoanalyze/priorityqueue/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/statistics/handle/autoanalyze/refresher/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down