How to Cancel a Running Auto Analyze Table Operation in TiDB?

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

Original topic: tidb 如何取消正在运行的auto analyze table操作?

| username: DBRE

[TiDB Usage Environment] Production Environment
[TiDB Version] 5.2.2
[Encountered Problem: Problem Phenomenon and Impact]
How to cancel the auto analyze table that is currently running in TiDB? The SQL execution time has increased significantly, affecting the business.

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

Automatic analyze table runs in a single thread, so it should not affect database performance. You can also adjust the analyze time:

SET GLOBAL tidb_auto_analyze_start_time='22:00 +0800';
SET GLOBAL tidb_auto_analyze_end_time='08:00 +0800';

Let it analyze the table during off-peak hours.

| username: DBRE | Original post link

  1. From the Duration, it seems to be affected, and the business has also reported timeouts.

  2. The time has also been adjusted, and the tidb-server running the analyze table has been restarted. The analyze table has been migrated to another tidb-server. Is the time zone setting incorrect?
    tidb_auto_analyze_end_time | 03:00 +0000 |
    tidb_auto_analyze_start_time | 00:00 +0000

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

Run date -R on the server to check the time zone. The time zone for China is +0800.

| username: DBRE | Original post link

Okay, I’ll make some changes.
]# date -R
Wed, 13 Sep 2023 10:08:45 +0800

| username: TiDBer_5cwU0ltE | Original post link

Stop the analysis for a day and see if it still times out. Why do I feel like it doesn’t have much to do with the analysis?

| username: Kongdom | Original post link

You can keep an eye on the slow queries in the Dashboard during this period, and the automatically analyzed queries will also be counted here.

| username: DBRE | Original post link

How to stop it?

| username: DBRE | Original post link

The focus is not on the issue; I want to ask how to stop the currently running auto analyze table. :joy:

| username: Kongdom | Original post link

Can the KILL statement be stopped?

| username: DBRE | Original post link

auto analyze table, cannot see it in show processlist

| username: Kongdom | Original post link

This should be the specific statement executed, analyze table xxx.

| username: DBRE | Original post link

No, the automatic analyze in TiDB cannot be seen in the show processlist, so you can’t directly kill the TiDB ID.

| username: Kongdom | Original post link

:thinking: No way, when we used v5.1 to automatically analyze at night, we could see the statements in the Dashboard. Isn’t it the same logic?

| username: DBRE | Original post link

  1. The data displayed on the Dashboard comes from the slow log, right? The slow log does indeed record the SQL for auto analyze.
  2. show processlist indeed does not have it.
| username: 像风一样的男子 | Original post link

DDL and DML will also be recorded in the slow query log, and you can see them in the dashboard. Analyze should be considered a DDL statement and will not be listed in the processlist.

| username: Kongdom | Original post link

:astonished: Okay, I really didn’t notice it before.

| username: 昵称想不起来了 | Original post link

After changing the execution time, is there still a delay during the previous time period?

| username: DBRE | Original post link

After further analysis, the high latency issue still occurred after completing the analyze. It was eventually identified that there was a BR backup. After killing the BR process, the latency returned to normal levels :joy:. However, I still want to know if there is a way to terminate the currently running auto analyze table operation.

| username: DBRE | Original post link

The root cause of the high latency was ultimately not auto analyze table :sob: