Skip to content

Commit

Permalink
executor: AnalyzePartitionConcurrency is not more than number of task (
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Nov 13, 2023
1 parent ba7fe19 commit 5b56cd5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/dbterror/exeerrors"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/mathutil"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tipb/go-tipb"
"go.uber.org/zap"
Expand Down Expand Up @@ -184,7 +185,7 @@ func (e *AnalyzeExec) Next(ctx context.Context, _ *chunk.Chunk) error {
// 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)
err = e.handleResultsError(ctx, concurrency, needGlobalStats, globalStatsMap, resultsCh)
err = e.handleResultsError(ctx, concurrency, needGlobalStats, globalStatsMap, resultsCh, len(tasks))
for _, task := range tasks {
if task.colExec != nil && task.colExec.memTracker != nil {
task.colExec.memTracker.Detach()
Expand Down Expand Up @@ -275,10 +276,18 @@ func recordHistoricalStats(sctx sessionctx.Context, tableID int64) error {
}

// handleResultsError will handle the error fetch from resultsCh and record it in log
func (e *AnalyzeExec) handleResultsError(ctx context.Context, concurrency int, needGlobalStats bool,
globalStatsMap globalStatsMap, resultsCh <-chan *statistics.AnalyzeResults) error {
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
// If 'partitionStatsConcurrency' > 1, we will try to demand extra session from Domain to save Analyze results in concurrency.
// the concurrency of handleResultsError cannot be more than partitionStatsConcurrency
partitionStatsConcurrency = mathutil.Min(taskNum, partitionStatsConcurrency)
// If partitionStatsConcurrency > 1, we will try to demand extra session from Domain to save Analyze results in concurrency.
// 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 5b56cd5

Please sign in to comment.