很久前就读过MySQL姜大神的《MySQL技术内幕:Innodb存储引擎》一书,尤其是第4章关于表的部分早忘了,最近恰逢另一位大神讲解Innodb数据块结构,因此做了个实验,全当复习了。Innodb数据块里的行记录具体内容解读与行记录格式有关,这里有以compact行格式为例。实验做完,好多东西一下串联起来了,好书还得多温习几次,同时动手才是学习王道。
-
mysql> create table ilvtu(id int,name varchar(50));
-
Query OK, 0 rows affected (0.38 sec)
-
mysql> insert into ilvtu values(1,'YANGYANG');
-
Query OK, 1 row affected (0.04 sec)
-
-
mysql> insert into ilvtu values(1,'DONGXUAN');
-
Query OK, 1 row affected (0.01 sec)
-
-
mysql> insert into ilvtu values(1,'FENGHUA');
-
Query OK, 1 row affected (0.01 sec)
-
-
mysql> commit;
-
Query OK, 0 rows affected (0.00 sec)
-
*************************** 1. row ***************************
-
Name: ilvtu
-
Engine: InnoDB
-
Version: 10
-
Row_format: Compact
-
Rows: 3
-
Avg_row_length: 5461
-
Data_length: 16384
-
Max_data_length: 0
-
Index_length: 0
-
Data_free: 0
-
Auto_increment: NULL
-
Create_time: 2016-07-02 19:30:23
-
Update_time: NULL
-
Check_time: NULL
-
Collation: utf8_general_ci
-
Checksum: NULL
-
Create_options:
-
Comment:
-
1 row in set (0.00 sec)
-
-
[root@master py_innodb_page_type]# python py_innodb_page_info.py -v /app/data/test/ilvtu.ibd
-
page offset 00000000, page type <File Space Header>
-
page offset 00000001, page type <Insert Buffer Bitmap>
-
page offset 00000002, page type <File Segment inode>
-
page offset 00000003, page type <B-tree Node>, page level <0000>
-
page offset 00000000, page type <Freshly Allocated Page>
-
page offset 00000000, page type <Freshly Allocated Page>
-
Total number of page: 6:
-
Freshly Allocated Page: 2
-
Insert Buffer Bitmap: 1
-
File Space Header: 1
-
B-tree Node: 1
-
File Segment inode: 1
-
-
-
[root@master ~]# hexdump -Cv /app/data/test/ilvtu.ibd >./ilvtu_block.txt
-
-
[root@master ~]# head -n 2 ilvtu_block.txt #第1块前32节
-
00000000 2d 72 54 98 00 00 00 00 00 00 00 00 00 00 00 00 |-rT.............|
-
00000010 00 00 00 00 85 69 93 24 00 08 00 00 00 00 00 00 |.....i.$........| #第26个节表:08代表页的类型,File space header
-
-
-
[root@master ~]# head -n 1026 ilvtu_block.txt|tail -n 2 #第2块前32字节
-
00004000 e7 79 36 83 00 00 00 01 00 00 00 00 00 00 00 00 |.y6.............|
-
00004010 00 00 00 00 85 69 86 ff 00 05 00 00 00 00 00 00 |.....i..........| #第26字节,05代表insert buffer bitmap
-
-
[root@master ~]# head -n 2050 ilvtu_block.txt|tail -n 2
-
00008000 83 7d 1f e4 00 00 00 02 00 00 00 00 00 00 00 00 |.}..............|
-
00008010 00 00 00 00 85 69 93 24 00 03 00 00 00 00 00 00 |.....i.$........| #0x0003代表索引页
-
-
[root@master ~]# head -n 3074 ilvtu_block.txt|tail -n 2
-
0000c000 a1 a3 c2 67 00 00 00 03 ff ff ff ff ff ff ff ff |...g............|
-
0000c010 00 00 00 00 85 69 9e a4 45 bf 00 00 00 00 00 00 |.....i..E.......| #045bf代表为数据节点,b-tree node
-
-
[root@master ~]# head -n 4098 ilvtu_block.txt|tail -n 2
-
00010000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
-
00010010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0x0000表示可用页
-
-
#数据页具体内容分析
-
-
#一行代表16字节
-
[root@master ~]# head -n 3094 ilvtu_block.txt|tail -n 22
-
#u前38字节为文件头
-
#前4个节a1 a3 c2 67为checksum
-
#第5-8个字节00 00 00 03,指定页的偏移量,表明为第4个页
-
#第9-12个字节ff ff ff ff,当前页的上一个页,只有为数据页时,才有具体意义值
-
#第13-16个节ff ff ff ff,当前页的下一个页,同上
-
#第17-24个字节代表该页最近被修改的日志序列位置LSN,00 00 00 00 85 69 9e a4
-
#第25-26字节,表示页的类型,45 bf表示为数据页
-
#第27-34字节,共8字节,00 00 00 00 00 00 00 00,只有属于系统表空间时才有意义
-
#第35-38字节,共4字节,00 00 00 69,代表属于哪个表空间,SPACE_ID
-
-
-
-
#第39-40字节,共2字节,代表存储页目录中的槽位(slot)数,00 02,代表2个slot
-
#第41-42字节,00 e9,代表空闲空间偏移量0000c000+00c9=0000c0e9
-
#第43-44字节,00 05,表示行数,因为表的格式为COMPAT,初始后为00 02,因些相减为3条记录
-
#第45-46字节,00 00,共2字节,存放可重用空间的首指针
-
#第47-48字节,00 00,共2字节,
-
#第49-50字节,00 cb, 0000c000+00cb=0000c0cb,代表最后一条记录插入的位置偏移量
-
#第51-52字共,共2字节,代表最后插入的方向00 02,代表向右增长
-
#第53-54字节,共2字节,代表连续插入的记录数,00 02,代表连续插入2条
-
#第55-56字节,共2字节,代表页中记录数,00 03代表有3条记录
-
#第57-64字节,共8字节,00 00 00 00 00 00 00 00
-
#第65-66字节,共2字节,00 00 代表叶子节点
-
#第67-74字节,共8字节,索引ID,00 00 00 00 00 00 00 dd
-
#第65-84字节,共10字节, 00 00 00 69 00 00 00 02 00 f2 代表B+树数据页非叶子节点所在段的段头
-
#第84-95字节,共10字节,代表B+树数据页所在段的段头,00 00 00 69 00 00 00 02 00 32
-
-
#第96-100字节,共5字节,01 00 02 00 1c,infimun记录头
-
#第101-108字节,共8字节,69 6e 66 69 6d 75 6d 00,infimun字节
-
-
第108-112字节,共5字节,04 00 0b 00 00,suprenum记录头
-
第113-120字节,共8字节,73 75 70 72 65 6d 75 6d,suprenum记录
-
-
-
-
0000c000 a1 a3 c2 67 00 00 00 03 ff ff ff ff ff ff ff ff |...g............|
-
0000c010 00 00 00 00 85 69 9e a4 45 bf 00 00 00 00 00 00 |.....i..E.......|
-
0000c020 00 00 00 00 00 69 00 02 00 e9 80 05 00 00 00 00 |.....i..........|
-
0000c030 00 cb 00 02 00 02 00 03 00 00 00 00 00 00 00 00 |................|
-
0000c040 00 00 00 00 00 00 00 00 00 dd 00 00 00 69 00 00 |.............i..|
-
0000c050 00 02 00 f2 00 00 00 69 00 00 00 02 00 32 01 00 |.......i.....2..|
-
0000c060 02 00 1c 69 6e 66 69 6d 75 6d 00 04 00 0b 00 00 |...infimum......|
-
0000c070 73 75 70 72 65 6d 75 6d
-
-
##往后行记录内容
-
#从121字节开始
-
-
#第一条记录
-
#第121字节,08变长字段长度为8,NAME字段值‘YANGYANG’为变长字段,8字节
-
#第122字节,00,NULL标记
-
#第123-127字节,共5字节,00 00 10 00 26,记录头
-
#第128-133字节,共6字节,ROWID,00 00 00 04 c2 00
-
#第134-139字共,共6字节,事务ID,00 00 00 00 75 0a
-
#第140-146字节,共7字节,8a 00 00 01 b8 01 10,回滚段ID,指向UNDO回滚段地址
-
#第147-150字节,共4节,ID字段所占固定长度,80 00 00 01
-
#第151-158字节,共8字节,变长字段NAME占用,‘59 41 4e 47 59 41 4e 47’,转换成字符串,为'YANGYANG'
-
-
0000c070 08 00 00 00 10 00 26 00 |supremum......&.|
-
0000c080 00 00 04 c2 00 00 00 00 00 75 0a 8a 00 00 01 b8 |.........u......|
-
0000c090 01 10 80 00 00 01 59 41 4e 47 59 41 4e 47
-
-
#第二条记录
-
0000c090 08 00 |......YANGYANG..|
-
0000c0a0 00 00 18 00 26 00 00 00 04 c2 01 00 00 00 00 75 |....&..........u|
-
0000c0b0 0b 8b 00 00 01 99 01 10 80 00 00 01 44 4f 4e 47 |............DONG|
-
0000c0c0 58 55 41 4e 07 00 00 00 20 ff a5 00 00 00 04 c2 |XUAN.... .......| //20字节所在位置为
-
0000c0d0 02 00 00 00 00 75 10 8e 00 00 01 4e 01 10 80 00 |.....u.....N....|
-
0000c0e0 00 01 46 45 4e 47 48 55 41 00 00 00 00 00 00 00 |..FENGHUA.......| //46 45 4e 47 48 55 41 对应‘FENGHUA
阅读(4228) | 评论(0) | 转发(0) |