Analyze Issues

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

Original topic: analyze 问题

| username: cheng

[TiDB Usage Environment] Production Environment
[Problem Phenomenon and Impact]

A table in production shows a health score of 0

This causes the production to continuously trigger automatic analyze operations, but I have set the time for automatic analyze.

  1. It can be automatically triggered but not within the time I set. What’s going on?

  2. Why is the health score still 0 even after executing analyze?
| username: buddyyuan | Original post link

  1. The parameters are set incorrectly. They should be set to:
    00:00 +0800
    07:00 +0800
    This way, it will execute from midnight to 7 AM.

  2. Check the data volume of this table.

| username: cheng | Original post link

The parameters have been changed. I’ll observe it further. The table’s data volume is not large, only 140,000.

| username: cheng | Original post link

After changing the parameters, it seems that the analyze operation is indeed not running. The initial value of the parameter is +0000, and I only changed the front part when I modified it. :joy:

So why didn’t the automatically performed analyze take effect? The health value is still 0. For other tables, the health value becomes 100 after I manually execute analyze.

| username: cheng | Original post link

It takes effect after manual execution.

| username: xiaohetao | Original post link

Manual collection definitely works. Before manual collection, when was the last time statistics were collected for the table with a health score of 0?

| username: xiaohetao | Original post link

After changing the parameter, it seems that the analyze operation indeed stopped running. The initial value of the parameter was +0000, and I only changed the front part when I modified it.

So why didn’t the automatically performed analyze take effect? The health value is still 0, but for other tables, the health value becomes 100 after I manually execute analyze.

The time you changed is set to execute from midnight to 7 AM. If it doesn’t pass through that time period, analyze won’t be executed, and the health value will remain the same.

| username: xiaohetao | Original post link

The reason for triggering analyze when executing SQL in the production environment should be caused by the value of tidb_auto_analyze_ratio, because the health of the table is already 0, meaning the table content has been modified;

As shown in your image, the tidb_auto_analyze_ratio is configured to the default value of 0.5, which means that analyze is triggered when more than 50% of the rows in the table are updated;

Of course, the main culprit is still that analyze did not automatically execute according to the designed time.

| username: cheng | Original post link

How do you check the last collection time of the statistics?

| username: cheng | Original post link

At first, the time zone was incorrect. The +0800 mentioned above is correct. After changing it to +0800, it no longer triggers. The current issue is that the automatically triggered analyze is not taking effect. Before I modified the parameters, analyze was being triggered continuously, but the health value remained at 0. Only after I manually triggered it did the health value become 100.

| username: alfred | Original post link

Was the table subjected to a large number of DML operations after the automatic analyze?

| username: cheng | Original post link

No, after analyze was triggered, it kept triggering because it didn’t take effect. You can see from my screenshot that after I manually triggered it, the health value became 100. This indicates that the automatic trigger did not take effect.

| username: h5n1 | Original post link

| username: xiaohetao | Original post link

show analyze status; Displays the start time of statistics for each table in each database

| username: xiaohetao | Original post link

At the beginning, the time zone was incorrect. The +0800 mentioned above is correct. After changing it to +0800, it no longer triggers. The current issue is that the automatically triggered analyze did not take effect. Before I modified the parameter, analyze was always triggered, but the health value was always 0. After I manually triggered it, the health value became 100.

Before you modified it, the time was +0000. For our time zone, the time period you set just happened to include our working hours, which, combined with the tidb_auto_analyze_ratio parameter value, triggered the statistics.

After changing it to +0800, you can check if statistics are being done at night.

| username: cheng | Original post link


I already changed this earlier.

| username: xiaohetao | Original post link

Hmm, after making the changes, there should be statistical information available by tonight, right? (assuming the tidb_auto_analyze_ratio conditions are met)

| username: cheng | Original post link

My current problem is why the automatic trigger of analyze did not take effect. You can check my picture and the description below.

| username: xiaohetao | Original post link

  1. What does it mean when analyze is triggered but not effective?
  2. So far, are there any tables with a health score below 50?
  3. Check the last time statistics were collected for each table?
| username: cheng | Original post link

  1. First of all, I think since we are helping others solve problems, we should definitely first understand their issues and responses, right?
  2. In my question, I posted a picture showing that the dashboard continuously executes analyze table on the same table. The health value of the table remains at 0 until I manually execute analyze table, after which the health value becomes 100. Does this indicate that the analyze table automatically executed by TiDB before my manual execution was ineffective?