-- 1. 查看行结构
mysql> show table status like 'course'\G
*************************** 1. row ***************************
Name: course
Engine: InnoDB
Version: 10
Row_format: Dynamic
Rows: 3
Avg_row_length: 5461
Data_length: 16384
Max_data_length: 0
Index_length: 0
Data_free: 0
Auto_increment: NULL
Create_time: 2022-08-04 14:44:18
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
-- 2.行记录的内部结构(注意隐藏列:事务ID和rowId):compact
-- 结论:compact格式下的null不占存储空间
______________________________________________________________
| 变长字段长度列表 | NULL标志位 | 头信息 | 列1数据 | 列2数据 | .... |
______________________________________________________________
mysql> select * from mytest\G
*************************** 1. row ***************************
t1: a
t2: bb
t3: bb
t4: ccc
*************************** 2. row ***************************
t1: d
t2: ee
t3: ee
t4: fff
*************************** 3. row ***************************
t1: d
t2: NULL
t3: NULL
t4: fff
3 rows in set (0.00 sec)
Compact:
0000c070 73 75 70 72 65 6d 75 6d 03 02 01 00 00 00 10 00 |supremum........|
0000c080 2c/00 00 00 02 c4 00/00 00 0d bf bb 01/e7 00 00 |,...............|
0000c090 05 10 01 10/61 62 62 62 62 20 20 20 20 20 20 20 |....abbbb |
0000c0a0 20 63 63 63/03 02 01 00 00 00 18 00 2b 00 00 00 | ccc........+...|
0000c0b0 02 c4 01 00 00 0d bf bb 10 ef 00 00 01 cf 01 10 |................|
0000c0c0 64 65 65 65 65 20 20 20 20 20 20 20 20 66 66 66 |deeee fff|
0000c0d0 /03 01/06/00 00 20 ff 98/ 00 00 00 02 c4 02/00 00 |..... ..........|
0000c0e0 0d bf bc 47/ab 00 00 01 6b 01 10/64 66 66 66 00 |...G....k..dfff.|------>这里是ROW=3的数据
可以看出在compact模式下,null不占空间
/*03 02 01*/ 变长字段长度的列表:逆序排列。当前表的变长字段的长度按顺序排列是1,2,3,则逆序即为3、2、1
/*00*/ 当前行是否有NULL值
/*00 00 10 00 2c*/ Row Header 固定5字节,00 2c指偏移量,当前位置+这个偏移量=下行记录的起始位置
/*00 00 00 02 c4 00*/ RowID:6字节
/*00 00 0d bf bb 01*/ Transation ID:6字节
/*e7 00 00 05 10 01 10*/ Roll Pointer回滚指针:7字节
/*61*/ 列1数据
/*62 62*/ 列2数据
/*62 62 20 20 20 20 20 20 20 20*/ 列3数据:因为这个字段是定长字段,所以不足的位数需要补齐空格
/*63 63 63*/ 列4的数据
-- 以下同理推出row=2的数据和row=3的数据
关于mysql的行内部结构
最新推荐文章于 2024-07-25 12:40:55 发布