Skip to content

Commit 383b908

Browse files
0xPoeti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#57258
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 4c32fcc commit 383b908

File tree

5 files changed

+1540
-2
lines changed

5 files changed

+1540
-2
lines changed

pkg/statistics/handle/autoanalyze/priorityqueue/dynamic_partitioned_table_analysis_job.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ func (j *DynamicPartitionedTableAnalysisJob) analyzePartitionIndexes(
201201
sysProcTracker sysproctrack.Tracker,
202202
) {
203203
analyzePartitionBatchSize := int(variable.AutoAnalyzePartitionBatchSize.Load())
204+
// For version 2, analyze one index will analyze all other indexes and columns.
205+
// For version 1, analyze one index will only analyze the specified index.
206+
analyzeVersion := sctx.GetSessionVars().AnalyzeVersion
204207

205-
OnlyPickOneIndex:
206208
for indexName, partitionNames := range j.PartitionIndexes {
207209
needAnalyzePartitionNames := make([]any, 0, len(partitionNames))
208210
for _, partition := range partitionNames {
@@ -218,11 +220,21 @@ OnlyPickOneIndex:
218220
sql := getPartitionSQL("analyze table %n.%n partition", " index %n", end-start)
219221
params := append([]any{j.TableSchema, j.GlobalTableName}, needAnalyzePartitionNames[start:end]...)
220222
params = append(params, indexName)
223+
<<<<<<< HEAD
221224
exec.AutoAnalyze(sctx, statsHandle, sysProcTracker, j.TableStatsVer, sql, params...)
225+
=======
226+
success = exec.AutoAnalyze(sctx, statsHandle, sysProcTracker, j.TableStatsVer, sql, params...)
227+
if !success {
228+
return false
229+
}
230+
}
231+
// For version 1, we need to analyze all indexes.
232+
if analyzeVersion != 1 {
233+
>>>>>>> 1b490966afd (statistics: make sure PQ can analyze all indexes with stats version 1 (#57258))
222234
// Halt execution after analyzing one index.
223235
// This is because analyzing a single index also analyzes all other indexes and columns.
224236
// Therefore, to avoid redundancy, we prevent multiple analyses of the same partition.
225-
break OnlyPickOneIndex
237+
break
226238
}
227239
}
228240
}

pkg/statistics/handle/autoanalyze/priorityqueue/non_partitioned_table_analysis_job.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ func (j *NonPartitionedTableAnalysisJob) analyzeIndexes(
173173
if len(j.Indexes) == 0 {
174174
return
175175
}
176+
// For version 2, analyze one index will analyze all other indexes and columns.
177+
// For version 1, analyze one index will only analyze the specified index.
178+
analyzeVersion := sctx.GetSessionVars().AnalyzeVersion
179+
if analyzeVersion == 1 {
180+
for _, index := range j.Indexes {
181+
sql, params := j.GenSQLForAnalyzeIndex(index)
182+
if !exec.AutoAnalyze(sctx, statsHandle, sysProcTracker, j.TableStatsVer, sql, params...) {
183+
return false
184+
}
185+
}
186+
return true
187+
}
176188
// Only analyze the first index.
177189
// This is because analyzing a single index also analyzes all other indexes and columns.
178190
// Therefore, to avoid redundancy, we prevent multiple analyses of the same table.

0 commit comments

Comments
 (0)