Skip to content

TiDB can not update stats correctly after reorg some partitions #48226

@0xPoe

Description

@0xPoe

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 values (1, "a"), (11, "b"), (21, "c");
  3. Check the meta:
mysql> select * from mysql.stats_meta;
+--------------------+----------+--------------+-------+----------+
| version            | table_id | modify_count | count | snapshot |
+--------------------+----------+--------------+-------+----------+
| 445359109485625359 |      103 |            1 |     1 |        0 |
| 445359109485625364 |      104 |            1 |     1 |        0 |
| 445359109485625349 |      105 |            1 |     1 |        0 |
| 445359109485625364 |      102 |            3 |     3 |        0 |
+--------------------+----------+--------------+-------+----------+
4 rows in set (0.00 sec)
  1. Reorg partition p0 and p1. Merge p0 and p1 into pw: alter table pt reorganize partition p0, p1 into (partition pw values less than (20));
  2. Check the meta again:
mysql> select * from mysql.stats_meta;
+--------------------+----------+--------------+-------+----------+
| version            | table_id | modify_count | count | snapshot |
+--------------------+----------+--------------+-------+----------+
| 445359109485625359 |      103 |            1 |     1 |        0 |
| 445359109485625364 |      104 |            1 |     1 |        0 |
| 445359109485625349 |      105 |            1 |     1 |        0 |
| 445359109485625364 |      102 |            3 |     3 |        0 |
| 445359172675436552 |      107 |            0 |     0 |        0 |
+--------------------+----------+--------------+-------+----------+
5 rows in set (0.00 sec)

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

mysql> select * from mysql.stats_meta;
+--------------------+----------+--------------+-------+----------+
| version            | table_id | modify_count | count | snapshot |
+--------------------+----------+--------------+-------+----------+
-| 445359109485625359 |      103 |            1 |     1 |        0 |
-| 445359109485625364 |      104 |            1 |     1 |        0 |
| 445359109485625349 |      105 |            1 |     1 |        0 |
| 445359109485625364 |      102 |            3 |     3 |        0 |
+| 445359172675436552 |      107 |            2 |     2 |        0 |
+--------------------+----------+--------------+-------+----------+
5 rows in set (0.00 sec)

3. What did you see instead (Required)

mysql> select * from mysql.stats_meta;
+--------------------+----------+--------------+-------+----------+
| version            | table_id | modify_count | count | snapshot |
+--------------------+----------+--------------+-------+----------+
| 445359109485625359 |      103 |            1 |     1 |        0 |
| 445359109485625364 |      104 |            1 |     1 |        0 |
| 445359109485625349 |      105 |            1 |     1 |        0 |
| 445359109485625364 |      102 |            3 |     3 |        0 |
| 445359172675436552 |      107 |            0 |     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.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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions