@@ -217,9 +217,9 @@ func (e *AnalyzeColumnsExec) buildSamplingStats(
217217 }
218218 }()
219219
220- l := len (e .analyzePB .ColReq .ColumnsInfo ) + len (e .analyzePB .ColReq .ColumnGroups )
221- rootRowCollector := statistics .NewRowSampleCollector (int (e .analyzePB .ColReq .SampleSize ), e .analyzePB .ColReq .GetSampleRate (), l )
222- for range l {
220+ totalLen := len (e .analyzePB .ColReq .ColumnsInfo ) + len (e .analyzePB .ColReq .ColumnGroups )
221+ rootRowCollector := statistics .NewRowSampleCollector (int (e .analyzePB .ColReq .SampleSize ), e .analyzePB .ColReq .GetSampleRate (), totalLen )
222+ for range totalLen {
223223 rootRowCollector .Base ().FMSketches = append (rootRowCollector .Base ().FMSketches , statistics .NewFMSketch (statistics .MaxSketchSize ))
224224 }
225225
@@ -251,7 +251,7 @@ func (e *AnalyzeColumnsExec) buildSamplingStats(
251251 for i := range samplingStatsConcurrency {
252252 id := i
253253 gp .Go (func () {
254- e .subMergeWorker (mergeCtx , taskCancel , mergeResultCh , mergeTaskCh , l , id )
254+ e .subMergeWorker (mergeCtx , taskCancel , mergeResultCh , mergeTaskCh , totalLen , id )
255255 })
256256 }
257257 // Merge the result from collectors.
@@ -342,7 +342,6 @@ func (e *AnalyzeColumnsExec) buildSamplingStats(
342342 return i .Handle .Compare (j .Handle )
343343 })
344344
345- totalLen := len (e .colsInfo ) + len (e .indexes )
346345 hists = make ([]* statistics.Histogram , totalLen )
347346 topns = make ([]* statistics.TopN , totalLen )
348347 fmSketches = make ([]* statistics.FMSketch , 0 , totalLen )
@@ -602,7 +601,7 @@ func (e *AnalyzeColumnsExec) subMergeWorker(
602601 cancel context.CancelCauseFunc ,
603602 resultCh chan <- * samplingMergeResult ,
604603 taskCh <- chan []byte ,
605- l int ,
604+ totalLen int ,
606605 index int ,
607606) {
608607 // Only close the resultCh in the first worker.
@@ -640,8 +639,8 @@ func (e *AnalyzeColumnsExec) subMergeWorker(
640639 }
641640 })
642641 // Keep one private collector per merge worker and flush it when taskCh is closed.
643- retCollector := statistics .NewRowSampleCollector (int (e .analyzePB .ColReq .SampleSize ), e .analyzePB .ColReq .GetSampleRate (), l )
644- for range l {
642+ retCollector := statistics .NewRowSampleCollector (int (e .analyzePB .ColReq .SampleSize ), e .analyzePB .ColReq .GetSampleRate (), totalLen )
643+ for range totalLen {
645644 retCollector .Base ().FMSketches = append (retCollector .Base ().FMSketches , statistics .NewFMSketch (statistics .MaxSketchSize ))
646645 }
647646 // Early-return paths need to release the worker-local collector explicitly.
@@ -671,7 +670,7 @@ func (e *AnalyzeColumnsExec) subMergeWorker(
671670 inflightRespSize = int64 (colResp .Size ())
672671 e .memTracker .Consume (inflightRespSize )
673672
674- subCollector := statistics .NewRowSampleCollector (int (e .analyzePB .ColReq .SampleSize ), e .analyzePB .ColReq .GetSampleRate (), l )
673+ subCollector := statistics .NewRowSampleCollector (int (e .analyzePB .ColReq .SampleSize ), e .analyzePB .ColReq .GetSampleRate (), totalLen )
675674 subCollector .Base ().FromProto (colResp .RowCollector , e .memTracker )
676675 statsHandle .UpdateAnalyzeJobProgress (e .job , subCollector .Base ().Count )
677676
0 commit comments