analyze is slow due to low concurrency
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
When using lightning, sometimes the analyze operation after importing data takes much longer time than usual. For example, in the following picture the first and second analyze takes about 1 min but the third analyze takes about 8 min.

The reason why the analyze operation is slow is related to region cache. After importing the data of a table, TiDB's region cache may still be outdated. When the analyze operation is triggered, TiDB may still think the table only occupies one region(but actually lots of regions), so the analyze operation only has one copTask and launches one copIteratorWorker(num(copIteratorWork) = min(concurrency param, num(copTask))). As a result, the analyze operation is slow due to low concurrency.
TiDB log for the normal analyze operation:

TiDB log for the slow analyze operation:

### 2. What did you expect to see? (Required)
The analyze operation after importing data takes roughly the same time as usual.
### 3. What did you see instead (Required)
The analyze operation after importing data takes much longer time than usual.
### 4. What is your TiDB version? (Required)
v5.2.1
Other versions may also have the problem.
Contributor guide
Assessment
This issue has not been assessed yet.