Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#47463
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
hawkingrei authored and ti-chi-bot committed Nov 13, 2023
1 parent ba7fe19 commit 00c7109
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ func (e *AnalyzeExec) Next(ctx context.Context, _ *chunk.Chunk) error {
for i := 0; i < concurrency; i++ {
e.wg.Run(func() { e.analyzeWorker(taskCh, resultsCh) })
}
<<<<<<< HEAD
=======
pruneMode := variable.PartitionPruneMode(sessionVars.PartitionPruneMode.Load())
// needGlobalStats used to indicate whether we should merge the partition-level stats to global-level stats.
needGlobalStats := pruneMode == variable.Dynamic
globalStatsMap := make(map[globalStatsKey]globalStatsInfo)
g, _ := errgroup.WithContext(ctx)
g.Go(func() error {
return e.handleResultsError(ctx, concurrency, needGlobalStats, globalStatsMap, resultsCh, len(tasks))
})

>>>>>>> 36c0298a51c (executor: AnalyzePartitionConcurrency is not more than number of task (#47463))
for _, task := range tasks {
prepareV2AnalyzeJobInfo(task.colExec, false)
AddNewAnalyzeJob(e.ctx, task.job)
Expand Down Expand Up @@ -275,10 +287,25 @@ func recordHistoricalStats(sctx sessionctx.Context, tableID int64) error {
}

// handleResultsError will handle the error fetch from resultsCh and record it in log
<<<<<<< HEAD
func (e *AnalyzeExec) handleResultsError(ctx context.Context, concurrency int, needGlobalStats bool,
globalStatsMap globalStatsMap, resultsCh <-chan *statistics.AnalyzeResults) error {
partitionStatsConcurrency := e.ctx.GetSessionVars().AnalyzePartitionConcurrency
// If 'partitionStatsConcurrency' > 1, we will try to demand extra session from Domain to save Analyze results in concurrency.
=======
func (e *AnalyzeExec) handleResultsError(
ctx context.Context,
concurrency int,
needGlobalStats bool,
globalStatsMap globalStatsMap,
resultsCh <-chan *statistics.AnalyzeResults,
taskNum int,
) error {
partitionStatsConcurrency := e.Ctx().GetSessionVars().AnalyzePartitionConcurrency
// the concurrency of handleResultsError cannot be more than partitionStatsConcurrency
partitionStatsConcurrency = min(taskNum, partitionStatsConcurrency)
// If partitionStatsConcurrency > 1, we will try to demand extra session from Domain to save Analyze results in concurrency.
>>>>>>> 36c0298a51c (executor: AnalyzePartitionConcurrency is not more than number of task (#47463))
// If there is no extra session we can use, we will save analyze results in single-thread.
if partitionStatsConcurrency > 1 {
dom := domain.GetDomain(e.ctx)
Expand Down

0 comments on commit 00c7109

Please sign in to comment.