Why Manual Execution is Fast but Recorded in Slow Query Logs

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

Original topic: 为什么手工执行很快却记录到慢查里

| username: TiDB_C罗

[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version]
[Reproduction Path] What operations were performed when the issue occurred
[Encountered Issue: Problem Phenomenon and Impact]
Manual execution is very fast, but it is recorded in the dashboard.

| username: TiDB_C罗 | Original post link

Index added and processed.

| username: Jasper | Original post link

The dashboard doesn’t show it as slow either, only 353ms. The execution time of the coprocessor includes the parallel execution time of TiKV, so it is not equivalent to our natural elapsed time. To see the real execution time of the query, just look at the “SQL Execution Time” at the top.

| username: caiyfc | Original post link

There is a configuration item that records SQL queries taking longer than 300ms as slow queries by default. You can adjust this according to your actual situation.

| username: 随缘天空 | Original post link

As for whether it is recorded in the slow query log, it depends on the slow query threshold set in your cluster topology file, which is 300ms by default. If you have manually set this value, any query exceeding the set threshold will be recorded in the slow query log.

| username: 气死人的萌新 | Original post link

I see that your execution time is 0.3 seconds, and the slow query is recorded based on the configuration for recording slow queries, which is generally 0.3 seconds. Judging by your slow query, it seems that this configuration has not been modified.

| username: Soysauce520 | Original post link

The default setting for the parameter tidb_slow_log_threshold is 300ms to record in the slow log. Slow queries can be viewed in the slow SQL file, and SQL analysis can be checked in the tidb_stmt_summary* tables.

To check the current setting:

select @@tidb_slow_log_threshold;

To check each TiDB server:

select * from information_schema.cluster_config where `key` ='instance.tidb_slow_log_threshold';
| username: 昵称想不起来了 | Original post link

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.