pingcap / pingcap/tidb

analyze is slow due to low concurrency

Open
#32,543 2 comments 0 reactions 0 assignees View on GitHub
affects-5.2 affects-6.0 sig/planner type/enhancement
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.

![20220222-201456](https://user-images.githubusercontent.com/30385241/155130397-d4b6da9d-32c8-4c77-8df5-cb4726c41dd8.png)

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:
![222](https://user-images.githubusercontent.com/30385241/155134089-72ff28da-a7da-4095-afba-caa6bb0f3846.png)

TiDB log for the slow analyze operation:
![1111](https://user-images.githubusercontent.com/30385241/155134124-352f0127-5cae-4e52-a717-5d10fedf34cf.png)

### 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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.