Skip to content

Commit

Permalink
statistics: fix panic when using wrong globalStats.Indices key (#35424)…
Browse files Browse the repository at this point in the history
… (#35543)

close #35421
  • Loading branch information
ti-srebot authored Nov 25, 2022
1 parent 1f143c6 commit ed8dda9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions statistics/handle/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ func (h *Handle) updateGlobalStats(tblInfo *model.TableInfo) error {

// Generate the new index global-stats
globalIdxStatsTopNNum, globalIdxStatsBucketNum := 0, 0
for idx := range tblInfo.Indices {
globalIdxStatsTopN := globalStats.Indices[int64(idx)].TopN
for _, idx := range tblInfo.Indices {
globalIdxStatsTopN := globalStats.Indices[idx.ID].TopN
if globalIdxStatsTopN != nil && len(globalIdxStatsTopN.TopN) > globalIdxStatsTopNNum {
globalIdxStatsTopNNum = len(globalIdxStatsTopN.TopN)
}
globalIdxStats := globalStats.Indices[int64(idx)]
globalIdxStats := globalStats.Indices[idx.ID]
if globalIdxStats != nil && len(globalIdxStats.Buckets) > globalIdxStatsBucketNum {
globalIdxStatsBucketNum = len(globalIdxStats.Buckets)
}
Expand All @@ -144,7 +144,7 @@ func (h *Handle) updateGlobalStats(tblInfo *model.TableInfo) error {
if globalIdxStatsBucketNum != 0 {
opts[ast.AnalyzeOptNumBuckets] = uint64(globalIdxStatsBucketNum)
}
newIndexGlobalStats, err := h.mergePartitionStats2GlobalStats(h.mu.ctx, opts, is, tblInfo, 1, []int64{int64(idx)})
newIndexGlobalStats, err := h.mergePartitionStats2GlobalStats(h.mu.ctx, opts, is, tblInfo, 1, []int64{idx.ID})
if err != nil {
return err
}
Expand Down

0 comments on commit ed8dda9

Please sign in to comment.