Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeatedly updating the same row will cause the stats_healthy to become low and generate wrong query plan #47523

Closed
King-Dylan opened this issue Oct 10, 2023 · 0 comments · Fixed by #50970

Comments

@King-Dylan
Copy link
Contributor

King-Dylan commented Oct 10, 2023

Report

Repeatedly updating the same row will cause the stats_healthy to become low, which affects the correctness of the execution plan

1. Minimal reproduce step (Required)

mysql> create table t(a int);
mysql> insert into t values(1),(1),(1),(1),(1),(1),(1),(1);
Query OK, 8 row affected (0.01 sec)
mysql> show stats_meta where table_name='t';
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | t          |                | 2023-10-10 16:36:50 |            0 |         8 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.00 sec)
mysql> update t set a=2 where a=1 limit 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 
mysql> update t set a=3 where a=2 limit 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> select * from t;
+------+
| a    |
+------+
|    3 |
|    1 |
|    1 |
|    1 |
|    1 |
|    1 |
|    1 |
|    1 |
+------+
8 rows in set (0.00 sec)

mysql> update t set a=4 where a=3 limit 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

2. What did you expect to see? (Required)

mysql> show stats_meta where table_name='t';
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | t          |                | 2023-10-10 16:40:47 |            1 |         8 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.00 sec)

mysql> show stats_healthy where table_name='t';
+---------+------------+----------------+---------+
| Db_name | Table_name | Partition_name | Healthy |
+---------+------------+----------------+---------+
| test    | t          |                |      88 |
+---------+------------+----------------+---------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

mysql> show stats_meta where table_name='t';
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | t          |                | 2023-10-10 16:40:47 |            3 |         8 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.00 sec)

mysql> show stats_healthy where table_name='t';
+---------+------------+----------------+---------+
| Db_name | Table_name | Partition_name | Healthy |
+---------+------------+----------------+---------+
| test    | t          |                |      12 |
+---------+------------+----------------+---------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

v6.5.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants