[stats] Auto Analyze Failed

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

Original topic: [stats] auto analyze failed

| username: xie123

[TiDB Usage Environment] Production Environment
[TiDB Version]
v5.4.0
[Reproduction Path] What operations were performed when the issue occurred
[Encountered Issue: Issue Phenomenon and Impact]
TiDB logs keep showing
[stats] auto analyze failed"] [sql=“analyze table DB.TABLE”] [cost_time=17.282654928s] [error=“[kv:8004]Transaction is too large, size: 105054135”]

Currently, the table no longer exists, and referring to the following link, drop stat didn’t work. What impact does setting the stats-lease parameter to 0 have? Is there any other way to prevent it from logging errors?

[Resource Configuration]
[Attachments: Screenshots/Logs/Monitoring]

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

Before v6.1.0, this switch was configured through the TiDB configuration file (performance.run-auto-analyze) to determine whether TiDB automatically updates table statistics as a background operation. It is recommended to disable automatic statistics collection, or disable it by setting the parameter SET GLOBAL tidb_auto_analyze_ratio = 0;, and then manually deploy tasks to collect statistics for the tables that need it.

| username: xie123 | Original post link

What issues might arise from disabling this statistic?

When insert, delete, and update statements occur, TiDB automatically updates the total number of rows in the table and the number of modified rows. This information is periodically persisted, with an update cycle of 20 * stats-lease. The default value of stats-lease is 3 seconds. If it is set to 0, it will not be automatically updated.

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

When stats-lease is set to 0s, TiDB will periodically read the statistics from the system tables and update the cached statistics in memory at 3-second intervals. However, it will not automatically modify the related system tables for statistics. Specifically, TiDB will no longer automatically modify these tables:

  • mysql.stats_meta: TiDB will no longer automatically record the number of rows modified in a table during a transaction, nor will it update this system table.
  • mysql.stats_histograms/mysql.stats_buckets and mysql.stats_top_n: TiDB will no longer automatically analyze and proactively update statistics.
  • mysql.stats_feedback: TiDB will no longer update the statistics of tables and indexes based on the partial statistics feedback from queried data.
| username: dba-kit | Original post link

This should be a bug in TiDB. However, if the table doesn’t exist and you just want to stop refreshing this table to avoid errors, you might try restarting the tidb-server that keeps reporting errors to clear the execution queue in memory.