Slow queries are fast when executed separately

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

Original topic: 慢查询语句单独拎出来查询又很快

| username: TiDBer_Y2d2kiJh

[TiDB Usage Environment] Production environment 2tidb 3pd 3tikv
[TiDB Version] V5.4.0
[Reproduction Path] In the monitoring slow query statement, it takes about 15 seconds to execute, but when extracted and queried in Navicat, it is fast, around 0.5 seconds. What is the situation and how should it be handled?
[Encountered Problem: Problem Phenomenon and Impact]
[Resource Configuration] Enter TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachment: Screenshot/Log/Monitoring]

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

Check the dashboard to see which part is slow.

| username: liuis | Original post link

Indeed, it might be related to the network environment and other factors.

| username: linnana | Original post link

It might be related to transactions and locks at that time.

| username: kkpeter | Original post link

Post the execution plan of the dashboard and take a look.

| username: 像风一样的男子 | Original post link

It is possible that the overall load on the cluster was relatively high at that time, resulting in higher average latency. Please check if the server resources are sufficient.

| username: redgame | Original post link

Compare the execution plans of the two runs to see if they are different.

| username: zhanggame1 | Original post link

It might be related to the load. Check the CPU and IO when it’s slow.

| username: Kongdom | Original post link

A certain slow query may not be the cause, but the result, influenced by other statements or issues.

| username: Anna | Original post link

Check the dashboard to see what the anomaly is.