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

primary key column's Histogram and TopN are not loaded after restarting TiDB #37548

Closed
xuyifangreeneyes opened this issue Sep 1, 2022 · 1 comment

Comments

@xuyifangreeneyes
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> use test;
Database changed
mysql> create table t(a int primary key);
Query OK, 0 rows affected (0.02 sec)

mysql> show create table t;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                  |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `a` int(11) NOT NULL,
  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> insert into t values (1), (2), (3), (4), (5), (6), (7), (8);
Query OK, 8 rows affected (0.00 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> analyze table t with 2 topn, 2 buckets;
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> show stats_meta;
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | t          |                | 2022-09-01 17:54:33 |            0 |         8 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.03 sec)

mysql> show stats_histograms;
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Update_time         | Distinct_count | Null_count | Avg_col_size | Correlation | Load_status | Total_mem_usage | Hist_mem_usage | Topn_mem_usage | Cms_mem_usage |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| test    | t          |                | a           |        0 | 2022-09-01 17:54:33 |              8 |          0 |            8 |           1 | allLoaded   |             427 |            313 |            114 |             0 |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
1 row in set (0.00 sec)

mysql> show stats_buckets;
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count | Repeats | Lower_Bound | Upper_Bound | Ndv  |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
| test    | t          |                | a           |        0 |         0 |     4 |       1 | 3           | 6           |    0 |
| test    | t          |                | a           |        0 |         1 |     6 |       1 | 7           | 8           |    0 |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
2 rows in set (0.01 sec)

mysql> show stats_topn;
+---------+------------+----------------+-------------+----------+-------+-------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Value | Count |
+---------+------------+----------------+-------------+----------+-------+-------+
| test    | t          |                | a           |        0 | 1     |     1 |
| test    | t          |                | a           |        0 | 2     |     1 |
+---------+------------+----------------+-------------+----------+-------+-------+
2 rows in set (0.00 sec)

Then restart TiDB and check stats.

show stats_meta;
show stats_histograms;
show stats_buckets;
show stats_topn;

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    | t          |                | 2022-09-01 17:54:38 |            8 |        16 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.04 sec)

mysql> show stats_histograms;
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Update_time         | Distinct_count | Null_count | Avg_col_size | Correlation | Load_status | Total_mem_usage | Hist_mem_usage | Topn_mem_usage | Cms_mem_usage |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| test    | t          |                | a           |        0 | 2022-09-01 17:54:33 |              8 |          0 |            8 |           1 | allLoaded   |             427 |            313 |            114 |             0 |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
1 row in set (0.00 sec)

mysql> show stats_buckets;
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count | Repeats | Lower_Bound | Upper_Bound | Ndv  |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
| test    | t          |                | a           |        0 |         0 |     4 |       1 | 3           | 6           |    0 |
| test    | t          |                | a           |        0 |         1 |     6 |       1 | 7           | 8           |    0 |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
2 rows in set (0.00 sec)

mysql> show stats_topn;
+---------+------------+----------------+-------------+----------+-------+-------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Value | Count |
+---------+------------+----------------+-------------+----------+-------+-------+
| test    | t          |                | a           |        0 | 1     |     1 |
| test    | t          |                | a           |        0 | 2     |     1 |
+---------+------------+----------------+-------------+----------+-------+-------+
2 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    | t          |                | 2022-09-01 17:54:38 |            8 |        16 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.04 sec)

mysql> show stats_histograms;
Empty set (0.00 sec)

mysql> show stats_buckets;
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count | Repeats | Lower_Bound | Upper_Bound | Ndv  |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
| test    | t          |                | a           |        0 |         0 |     4 |       1 | 3           | 6           |    0 |
| test    | t          |                | a           |        0 |         1 |     6 |       1 | 7           | 8           |    0 |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
2 rows in set (0.00 sec)

mysql> show stats_topn;
Empty set (0.00 sec)

4. What is your TiDB version? (Required)

mysql> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                   |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v5.4.0-1429-ga80078538
Edition: Community
Git Commit Hash: a80078538d366d55acfc34dd772b1977a720a9bc
Git Branch: master
UTC Build Time: 2022-09-01 09:50:59
GoVersion: go1.18.1
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
@xuyifangreeneyes xuyifangreeneyes added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner component/statistics labels Sep 1, 2022
@xuyifangreeneyes xuyifangreeneyes self-assigned this Sep 1, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 may-affects-6.2 may-affects-6.3 labels Sep 13, 2022
@xuyifangreeneyes xuyifangreeneyes added affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 labels Jan 10, 2023
@ti-chi-bot ti-chi-bot removed the may-affects-4.0 This bug maybe affects 4.0.x versions. label Jan 10, 2023
@qw4990 qw4990 removed affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-6.0 affects-6.2 affects-6.3 affects-6.4 labels Apr 28, 2024
@hawkingrei hawkingrei self-assigned this May 14, 2024
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.

8 participants