show-table-status
概要
之前也使用过 show table status 来查看过表的信息,但是并没有深入去看各个列的意义,现在准备系统的总结一下。
环境
使用 MySQL-8.0.32 环境
select @@version;
+-----------+
| @@version |
+-----------+
| 8.0.32 |
+-----------+
1 row in set (0.00 sec)
create table person(id bigint not null auto_increment primary key,
name varchar(32),
birthday datetime,
index idx_name(name));
Query OK, 0 rows affected (0.04 sec)
insert into person(name, birthday) values("tom", "2020-01-01"),("jerry", "2020-02-02"),("bob","2020-03-03");
Query OK, 0 rows affected (0.00 sec)
select * from person;
+----+-------+---------------------+
| id | name | birthday |
+----+-------+---------------------+
| 1 | tom | 2020-01-01 00:00:00 |
| 2 | jerry | 2020-02-02 00:00:00 |
| 3 | bob | 2020-03-03 00:00:00 |
+----+-------+---------------------+
3 rows in set (0.00 sec)
检查表状态
show table status like 'person' \G
*************************** 1. row ***************************
Name: person
Engine: InnoDB
Version: 10
Row_format: Dynamic
Rows: 3
Avg_row_length: 5461
Data_length: 16384
Max_data_length: 0
Index_length: 16384
Data_free: 0
Auto_increment: 4
Create_time: 2023-04-25 21:25:32
Update_time: 2023-04-25 21:27:11
Check_time: NULL
Collation: utf8mb4_0900_ai_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
各列的意义
列名 | 意义 |
---|---|
Name | 表名 |
Engine | 表采用的引擎 |
Version | 8.0 开始这个值会一直是 10 |
Row_format | 行的存储格式 |
Avg_row_length | 平均行的长度(这个应该也不准确) |
Data_length | 为聚集索引分配的页面数 * 页面大小 |
Max_data_length | Innodb 未使用 |
Index_length | 非聚集索引分配的页面数 * 页面大小 |
Data_free | 已经分配但是还没有使用的 extend |
Auto_increment | 下一个自增值 |
Create_time | 创建时间 |
Update_time | 更新时间(由于 change buffer 存在这个会滞后更新) |
Check_time | Innodb 这个值永远是 NULL |
Checksum | checksum 的值 |
Create_options | 创建表时的额外选项 |
Comment | 注释 |
详解 Data_free
分配了但是还没有使用的字节数。
对于 Innodb 表来说这个值就是表空间的空闲空间,一个表如果是在“共享表空间”的那么 Data_free 就是共享表空间的空闲空间。对于独立表空间也同事。
注意:表空间的空闲空间是以 extend 为单位的,没有空闲的 extend 并不代表就没有可用空间了,也就是说哪怕 Date_free 等于 0 了,表还是有可能继续写入的。
参考
https://dev.mysql.com/doc/refman/8.0/en/show-table-status.html