pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.93k stars 5.81k forks source link

analyze may block forever #56071

Open wjhuang2016 opened 6 days ago

wjhuang2016 commented 6 days ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reprod

Here is the TiDB's goroutine bb.txt

2. What did you expect to see? (Required)

N/A

3. What did you see instead (Required)

N/A

4. What is your TiDB version? (Required)

master

wjhuang2016 commented 6 days ago
func (e *AnalyzeExec) handleResultsErrorWithConcurrency(
    buildStatsConcurrency int,
    saveStatsConcurrency int,
    needGlobalStats bool,
    globalStatsMap globalStatsMap,
    resultsCh <-chan *statistics.AnalyzeResults,
) error {
    statsHandle := domain.GetDomain(e.Ctx()).StatsHandle()
    wg := util.NewWaitGroupPool(e.gp)
    saveResultsCh := make(chan *statistics.AnalyzeResults, saveStatsConcurrency)
    errCh := make(chan error, saveStatsConcurrency)
    enableAnalyzeSnapshot := e.Ctx().GetSessionVars().EnableAnalyzeSnapshot
    logutil.BgLogger().Info("start analyze save stats worker", zap.Int("saveStatsConcurrency", saveStatsConcurrency))
    for i := 0; i < saveStatsConcurrency; i++ {
        worker := newAnalyzeSaveStatsWorker(saveResultsCh, errCh, &e.Ctx().GetSessionVars().SQLKiller)
        ctx1 := kv.WithInternalSourceType(context.Background(), kv.InternalTxnStats)
        wg.Run(func() {
            worker.run(ctx1, statsHandle, enableAnalyzeSnapshot)
        })
    }

log:

TiDB 127.0.0.1:4000[analyze.go:417] ["start analyze save stats worker"] [saveStatsConcurrency=0]