@@ -201,8 +201,10 @@ func (j *DynamicPartitionedTableAnalysisJob) analyzePartitionIndexes(
201
201
sysProcTracker sysproctrack.Tracker ,
202
202
) {
203
203
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
204
207
205
- OnlyPickOneIndex:
206
208
for indexName , partitionNames := range j .PartitionIndexes {
207
209
needAnalyzePartitionNames := make ([]any , 0 , len (partitionNames ))
208
210
for _ , partition := range partitionNames {
@@ -218,11 +220,21 @@ OnlyPickOneIndex:
218
220
sql := getPartitionSQL ("analyze table %n.%n partition" , " index %n" , end - start )
219
221
params := append ([]any {j .TableSchema , j .GlobalTableName }, needAnalyzePartitionNames [start :end ]... )
220
222
params = append (params , indexName )
223
+ << << << < HEAD
221
224
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
+ >> >> >> > 1 b490966afd (statistics : make sure PQ can analyze all indexes with stats version 1 (#57258 ))
222
234
// Halt execution after analyzing one index.
223
235
// This is because analyzing a single index also analyzes all other indexes and columns.
224
236
// Therefore, to avoid redundancy, we prevent multiple analyses of the same partition.
225
- break OnlyPickOneIndex
237
+ break
226
238
}
227
239
}
228
240
}
0 commit comments