diff --git a/executor/analyze_col_v2.go b/executor/analyze_col_v2.go index 1d9913d5f23e3..98a40aaf79e4c 100644 --- a/executor/analyze_col_v2.go +++ b/executor/analyze_col_v2.go @@ -599,7 +599,7 @@ func (e *AnalyzeColumnsExecV2) subMergeWorker(resultCh chan<- *samplingMergeResu times := val.(int) for i := 0; i < times; i++ { e.memTracker.Consume(5 << 20) - time.Sleep(100 * time.Millisecond) + time.Sleep(10 * time.Millisecond) } }) retCollector := statistics.NewRowSampleCollector(int(e.analyzePB.ColReq.SampleSize), e.analyzePB.ColReq.GetSampleRate(), l) diff --git a/executor/analyzetest/analyze_test.go b/executor/analyzetest/analyze_test.go index 08ca17e2b2d1b..b85c41d28e14e 100644 --- a/executor/analyzetest/analyze_test.go +++ b/executor/analyzetest/analyze_test.go @@ -3094,6 +3094,8 @@ func TestGlobalMemoryControlForAnalyze(t *testing.T) { _, err := tk0.Exec(sql) require.NotNil(t, err) require.True(t, strings.Contains(err.Error(), "Out Of Memory Quota!")) + // sleep to wait all workers to consume memory and exit + time.Sleep(10 * time.Millisecond) runtime.GC() } @@ -3172,7 +3174,8 @@ func TestGlobalMemoryControlForAutoAnalyze(t *testing.T) { rs := tk.MustQuery("select fail_reason from mysql.analyze_jobs where table_name=? and state=? limit 1", "t", "failed") failReason := rs.Rows()[0][0].(string) require.True(t, strings.Contains(failReason, "Out Of Memory Quota!")) - + // sleep to wait all workers to consume memory and exit + time.Sleep(10 * time.Millisecond) childTrackers = executor.GlobalAnalyzeMemoryTracker.GetChildrenForTest() require.Len(t, childTrackers, 0) }