# 查看表的统计信息（D）
+ 查看直方图的信息:
```7
mysql> SHOW STATS_BUCKETS WHERE db_name = 'tpcc' AND table_name = 'orders';
+---------+------------+----------------+-------------+----------+-----------+--------+---------+---------------------+---------------------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count  | Repeats | Lower_Bound         | Upper_Bound         |
+---------+------------+----------------+-------------+----------+-----------+--------+---------+---------------------+---------------------+
| tpcc    | orders     |                | PRIMARY     |        1 |         0 |   1024 |       1 | (1, 1, 1)           | (1, 1, 1024)        |
| tpcc    | orders     |                | PRIMARY     |        1 |         1 |   2048 |       1 | (1, 1, 1025)        | (1, 1, 2048)        |
| tpcc    | orders     |                | PRIMARY     |        1 |         2 |   3072 |       1 | (1, 1, 2049)        | (1, 2, 72)          |
... ...
| tpcc    | orders     |                | PRIMARY     |        1 |       151 | 155648 |       1 | (6, 2, 1625)        | (6, 2, 2648)        |
| tpcc    | orders     |                | PRIMARY     |        1 |       152 | 156000 |       1 | (6, 2, 2649)        | (6, 2, 3000)        |
| tpcc    | orders     |                | idx_order   |        1 |         0 |   1024 |       1 | (1, 1, 1, 1867)     | (1, 1, 1024, 2497)  |
| tpcc    | orders     |                | idx_order   |        1 |         1 |   2048 |       1 | (1, 1, 1025, 2440)  | (1, 1, 2048, 2438)  |
... ...
| tpcc    | orders     |                | idx_order   |        1 |       151 | 155648 |       1 | (6, 2, 1625, 3000)  | (6, 2, 2648, 1474)  |
| tpcc    | orders     |                | idx_order   |        1 |       152 | 156000 |       1 | (6, 2, 2649, 1437)  | (6, 2, 3000, 1521)  |
+---------+------------+----------------+-------------+----------+-----------+--------+---------+---------------------+---------------------+
306 rows in set (0.01 sec)
```
-------------------------------------------------------------
查看表的统计信息
查看表的各种统计信息
- 查看表的元信息                  SHOW STATS_META [ShowLikeOrWhere];
- 查看表的健康状态              SHOW STATS_HEALTHY [ShowLikeOrWhere];
- 查看列的元信息                 SHOW STATS_HISTOGRAMS [ShowLikeOrWhere];
查看直方图的信息             SHOW STATS_BUCKETS [ShowLikeOrWhere];
```
mysql> SHOW STATS_BUCKETS WHERE db_name = 'tpcc' AND table_name = 'orders';
+---------+------------+----------------+-------------+----------+-----------+--------+---------+---------------------+---------------------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count  | Repeats | Lower_Bound         | Upper_Bound         |
+---------+------------+----------------+-------------+----------+-----------+--------+---------+---------------------+---------------------+
| tpcc    | orders     |                | PRIMARY     |        1 |         0 |   1024 |       1 | (1, 1, 1)           | (1, 1, 1024)        |
| tpcc    | orders     |                | PRIMARY     |        1 |         1 |   2048 |       1 | (1, 1, 1025)        | (1, 1, 2048)        |
| tpcc    | orders     |                | PRIMARY     |        1 |         2 |   3072 |       1 | (1, 1, 2049)        | (1, 2, 72)          |
... ...
| tpcc    | orders     |                | PRIMARY     |        1 |       151 | 155648 |       1 | (6, 2, 1625)        | (6, 2, 2648)        |
| tpcc    | orders     |                | PRIMARY     |        1 |       152 | 156000 |       1 | (6, 2, 2649)        | (6, 2, 3000)        |
| tpcc    | orders     |                | idx_order   |        1 |         0 |   1024 |       1 | (1, 1, 1, 1867)     | (1, 1, 1024, 2497)  |
| tpcc    | orders     |                | idx_order   |        1 |         1 |   2048 |       1 | (1, 1, 1025, 2440)  | (1, 1, 2048, 2438)  |
... ...
| tpcc    | orders     |                | idx_order   |        1 |       151 | 155648 |       1 | (6, 2, 1625, 3000)  | (6, 2, 2648, 1474)  |
| tpcc    | orders     |                | idx_order   |        1 |       152 | 156000 |       1 | (6, 2, 2649, 1437)  | (6, 2, 3000, 1521)  |
+---------+------------+----------------+-------------+----------+-----------+--------+---------+---------------------+---------------------+
306 rows in set (0.01 sec)
```
- 可以通过 SHOW STATS_META 来查看表的总行数以及修改的行数等信息。
- 可以通过 SHOW STAT_HEALTHY 来查看统计信息的健康度，并粗滤估计表上的统计信息是否准确。当健康度低于刚才提到的自动更新阈值 tidb_auto_analyze_ratio，优化器会在窗口期内自动进行统计信息的收集操作
- 可以通过 SHOW STATS_HISTOGRAMS 来查看列的不同值数量以及 NULL 数量等信息。该语句会输出所有列的不同值数量及 NULL 的数量等信息。
- 可以通过 STAT_BUCKETS 来查看直方图的每个桶的信息。从该例中我们可以看到，不仅有表的直方图信息，还有索引的直方图信息。
