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

TiDB can not update stats correctly after exchange a partition #47354

Closed
Tracked by #48126
Rustin170506 opened this issue Sep 28, 2023 · 0 comments · Fixed by #49043
Closed
Tracked by #48126

TiDB can not update stats correctly after exchange a partition #47354

Rustin170506 opened this issue Sep 28, 2023 · 0 comments · Fixed by #49043
Assignees
Labels
component/statistics severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@Rustin170506
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. Create a table: create table pt(a int, b varchar(10), index idx_b (b)) partition by range(a) (partition p0 values less than (10), partition p1 values less than (20), partition p2 values less than (30));
  2. Insert some data: insert into pt(a, b) values(1,'a'); insert into pt(a, b) values(5,'a');
  3. Check the meta:
mysql> select * from mysql.stats_meta;
+--------------------+----------+--------------+-------+----------+
| version            | table_id | modify_count | count | snapshot |
+--------------------+----------+--------------+-------+----------+
| 444565530978025482 |      103 |            2 |     2 |        0 |
| 444565516821987331 |      104 |            0 |     0 |        0 |
| 444565516821987336 |      105 |            0 |     0 |        0 |
| 444565530978025482 |      102 |            2 |     2 |        0 |
+--------------------+----------+--------------+-------+----------+
4 rows in set (0.00 sec)
  1. Create a new table: create table t1(a int, b varchar(10), index idx_b (b));
  2. Insert data to t1: insert into t1(a, b) values(1,'a');
  3. Check the meta again:
mysql> select * from mysql.stats_meta;
+--------------------+----------+--------------+-------+----------+
| version            | table_id | modify_count | count | snapshot |
+--------------------+----------+--------------+-------+----------+
| 444565530978025482 |      103 |            2 |     2 |        0 |
| 444565516821987331 |      104 |            0 |     0 |        0 |
| 444565516821987336 |      105 |            0 |     0 |        0 |
| 444565530978025482 |      102 |            2 |     2 |        0 |
| 444565546707976206 |      107 |            1 |     1 |        0 |
+--------------------+----------+--------------+-------+----------+
5 rows in set (0.00 sec)
  1. Exchange the partition: alter table pt exchange partition p0 with table t1;
  2. Check the meta:
mysql> show stats_meta;
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | t1         |                | 2023-09-28 14:35:15 |            2 |         2 |
| test    | pt         | global         | 2023-09-28 14:35:15 |            2 |         2 |
| test    | pt         | p0             | 2023-09-28 14:36:15 |            1 |         1 |
| test    | pt         | p1             | 2023-09-28 14:34:21 |            0 |         0 |
| test    | pt         | p2             | 2023-09-28 14:34:21 |            0 |         0 |
+---------+------------+----------------+---------------------+--------------+-----------+
5 rows in set (0.00 sec)

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

mysql> show stats_meta;
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | t1         |                | 2023-09-28 14:35:15 |            2 |         2 |
- | test    | pt         | global         | 2023-09-28 14:35:15 |            2 |         2 |
+ | test    | pt         | global         | 2023-09-28 14:35:15 |            1 |         1 |
| test    | pt         | p0             | 2023-09-28 14:36:15 |            1 |         1 |
| test    | pt         | p1             | 2023-09-28 14:34:21 |            0 |         0 |
| test    | pt         | p2             | 2023-09-28 14:34:21 |            0 |         0 |
+---------+------------+----------------+---------------------+--------------+-----------+
5 rows in set (0.00 sec)

3. What did you see instead (Required)

mysql> show stats_meta;
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | t1         |                | 2023-09-28 14:35:15 |            2 |         2 |
| test    | pt         | global         | 2023-09-28 14:35:15 |            2 |         2 |
| test    | pt         | p0             | 2023-09-28 14:36:15 |            1 |         1 |
| test    | pt         | p1             | 2023-09-28 14:34:21 |            0 |         0 |
| test    | pt         | p2             | 2023-09-28 14:34:21 |            0 |         0 |
+---------+------------+----------------+---------------------+--------------+-----------+
5 rows in set (0.00 sec)

4. What is your TiDB version? (Required)

mysql> SELECT tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                     |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.5.0-alpha-1-g22e9be7d4e
Edition: Community
Git Commit Hash: 22e9be7d4e440ec87cf5c8407866ca0a9b49c91a
Git Branch: master
UTC Build Time: 2023-09-28 06:24:13
GoVersion: go1.21.1
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
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

Successfully merging a pull request may close this issue.

1 participant