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

Truncating the hash partition in TiDB does not automatically delete old statistics and update the global stats #48235

Closed
Tracked by #48126
Rustin170506 opened this issue Nov 2, 2023 · 1 comment
Labels
component/statistics severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@Rustin170506
Copy link
Member

Rustin170506 commented Nov 2, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. Create a table: create table ht(a int, b varchar(10), index idx_b (b)) partition by hash(a) partitions 3;
  2. Insert some data: insert into ht values (1, "a"), (2, "b"), (3, "c");
  3. Check the meta:
mysql> select * from mysql.stats_meta;
+--------------------+----------+--------------+-------+----------+
| version            | table_id | modify_count | count | snapshot |
+--------------------+----------+--------------+-------+----------+
| 445360015141502990 |      103 |            1 |     1 |        0 |
| 445360015141502978 |      104 |            1 |     1 |        0 |
| 445360015141502985 |      105 |            1 |     1 |        0 |
| 445360015141502990 |      102 |            3 |     3 |        0 |
+--------------------+----------+--------------+-------+----------+
4 rows in set (0.00 sec)
  1. Truncate a partition p0: alter table ht truncate partition p0;
  2. Check the meta again:
mysql> select * from mysql.stats_meta;
+--------------------+----------+--------------+-------+----------+
| version            | table_id | modify_count | count | snapshot |
+--------------------+----------+--------------+-------+----------+
| 445360015141502990 |      103 |            1 |     1 |        0 |
| 445360015141502978 |      104 |            1 |     1 |        0 |
| 445360015141502985 |      105 |            1 |     1 |        0 |
| 445360015141502990 |      102 |            3 |     3 |        0 |
| 445360043190910995 |      107 |            0 |     0 |        0 |
+--------------------+----------+--------------+-------+----------+
5 rows in set (0.00 sec)

mysql> show stats_meta;
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | ht         | global         | 2023-11-02 16:27:11 |            3 |         3 |
| test    | ht         | p0             | 2023-11-02 16:28:58 |            0 |         0 |
| test    | ht         | p1             | 2023-11-02 16:27:11 |            1 |         1 |
| test    | ht         | p2             | 2023-11-02 16:27:11 |            1 |         1 |
+---------+------------+----------------+---------------------+--------------+-----------+
4 rows in set (0.01 sec)

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

  1. Drop the old stats.
  2. Update global stats correctly.

3. What did you see instead (Required)

mysql> select * from mysql.stats_meta;
+--------------------+----------+--------------+-------+----------+
| version            | table_id | modify_count | count | snapshot |
+--------------------+----------+--------------+-------+----------+
| 445360015141502990 |      103 |            1 |     1 |        0 |
| 445360015141502978 |      104 |            1 |     1 |        0 |
| 445360015141502985 |      105 |            1 |     1 |        0 |
| 445360015141502990 |      102 |            3 |     3 |        0 |
| 445360043190910995 |      107 |            0 |     0 |        0 |
+--------------------+----------+--------------+-------+----------+
5 rows in set (0.01 sec)

4. What is your TiDB version? (Required)

mysql> select tidb_version();
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                      |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.6.0-alpha-69-gbf8c728934
Edition: Community
Git Commit Hash: bf8c728934c7376765ddd943fd302fcb65af4bf0
Git Branch: master
UTC Build Time: 2023-11-01 08:29:41
GoVersion: go1.21.1
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
@Rustin170506
Copy link
Member Author

Fixed by #49362

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/statistics severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

1 participant