How to Resolve High Wait Time in Slow Queries

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 慢查询 wait Time 比较大,怎么解决

| username: 大飞飞呀

【TiDB Usage Environment】Production Environment
【TiDB Version】
【Reproduction Path】What operations were performed when the issue occurred
【Encountered Issue: Issue Phenomenon and Impact】


The wait time is relatively long, what is the reason?
【Resource Configuration】Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
【Attachments: Screenshots/Logs/Monitoring】

| username: xfworld | Original post link

Check the execution plan and the actual execution plan

explain sql
explain analyze sql

You can compare them.

| username: tidb菜鸟一只 | Original post link

  • Wait_time: This represents the total waiting time of this statement in TiKV. Since the number of Coprocessor threads in TiKV is limited, requests will queue up when all Coprocessor threads are busy. When some requests in the queue take a long time, the waiting time for subsequent requests will increase.
    In simple terms, it means that all Coprocessor threads in TiKV are fully occupied, and the waiting time for Coprocessor requests.
| username: cy6301567 | Original post link

Increase the machine’s CPU configuration, add KV nodes, and distribute hotspot data.

| username: ajin0514 | Original post link

The coprocessor is fully loaded, it is recommended to add more resources.