??????????????????????????????
?? ?????????????????????????????????????????????????????????????InnoDB???????????????????????????????????????????????????????????????16KB???InnoDB????????????????????????????????????????????????????????????????????????????????????????????????????????????Insert Buffer?????????????????????INODE?????????????????????undo??????????????????????????????????????????????????????????????????????????????????????????????????????????????????~ ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????INDEX)????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????
????????????????????????????????????16KB???????????????????????????????????????????????????????????????????????????????????????????????????????????????

??????????????????????????????InnoDB?????????????????????????????????????????????7????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????7????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????
?????????7??????????????????????????????????????????????????????????????????????????????????????????User Records???????????????????????????????????????????????????????????????User Records?????????????????????????????????????????????????????????Free Space??????????????????????????????????????????????????????????????????????????????????????????User Records????????????Free Space????????????????????????User Records????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????User Records?????????????????????InnoDB???????????????????????????????????????????????????????????????????????????????????????????????????????????????User Records???????????? ??????????????????????????????????????????????????????????????????
3.1 ????????????????????????
?????????????????????????????????????????????????????????
mysql> CREATE TABLE page_demo(
-> c1 INT,
-> c2 INT,
-> c3 VARCHAR(10000),
-> PRIMARY KEY (c1)
-> ) CHARSET=ascii ROW_FORMAT=Compact;
Query OK, 0 rows affected (0.03 sec)
??????????????????page_demo??????3???????????????c1????????????????????????????????????c3???????????????????????????????????????????????????????????????c1???????????????????????????????????????????????????InnoDB?????????????????????????????????????????????row_id????????????????????????????????????????????????ascii???????????????Compact??????????????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????5???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Compact???????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????page_demo???????????????????????????????????????????????????????????????c1???c2???c3????????????????????????????????????page_demo???????????????????????????
mysql> INSERT INTO page_demo VALUES(1, 100, 'aaaa'), (2, 200, 'bbbb'), (3, 300, 'cccc'),
(4, 400, 'dddd');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
?????????????????????????????????????????????User Records?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????User Records????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
-
delete_mask
?????????????????????????????????????????????????????????1????????????????????????0?????????????????????????????????????????????1???????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????~ ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
-
min_rec_mask
B+?????????????????????????????????????????????????????????????????????????????????B+??????????????????????????????????????????????????????????????????????????????????????????????????????????????????min_rec_mask?????????0???????????????????????????B+??????????????????????????????????????????
-
n_owned
?????????????????????????????????????????????????????????????????????
-
heap_no
????????????????????????????????????????????????????????????????????????????????????????????????4??????????????????????????????????????????2???3???4???5.?????????????????????????????????????????????heap_no??????0???1?????????????????????????????????InnnoDB????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????~???????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????4??????????????????????????????1???2???3???4??????????????????4?????????????????????????????????????????????
??????????????????????????????????????????????????????????????????InnoDB??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????5?????????????????????????????????8???????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????????????User Records??????????????????????????????????????????Infimum+Supermum???????????????????????????
???????????????????????????????????????????????????????????????heap_no????????????0???1??????????????????????????????????????????
-
record_type
???????????????????????????????????????????????????4?????????????????????0?????????????????????1??????B+???????????????????????????2?????????????????????3??????????????????????????????????????????????????????????????????????????????????????????????????????????????????record_type?????????0????????????????????????????????????record_type????????????2???3?????????record_type???1??????????????????????????????????????????????????????????????????
-
next_record
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????next_record??????32??????????????????????????????????????????????????????????????????32??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????infimum?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Supermum????????????????????????????????????????????????????????????????????????next_record????????????????????????????????????????????????next_record????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????next_record?????????0??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
mysql> DELETE FROM page_demo WHERE c1 = 2;
Query OK, 1 row affected (0.02 sec)
???????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????
- ???????????????????????????????????????????????????????????????????????????delete_mask????????????1.
- ??????????????????next_record????????????0????????????????????????????????????????????????
- ??????????????????next_record????????????3????????????
-
??????????????????????????????????????????????????????n_owned??????5?????????4????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????InnoDB???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
tips:
??????????????????next_record????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????NULL?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????~
?????????
?????????????????????????????????????????????????????????????????????next_record????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????Page Directory(?????????)
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????????????Infimum??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????4??????????????????????????????????????????4????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????InnoDB??????????????????????????????????????????????????????????????????????????????????????????6???????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????InnnoDB??????????????????????????????????????????????????????????????????????????????????????????????????????
- ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
- ??????????????????????????????????????????????????????????????????????????????????????????n_owned????????????????????????????????????????????????????????????????????????????????????
- ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Page Directory???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Slot???,????????????????????????????????????????????????
??????????????????page_demo???????????????????????????6??????InnoDB??????????????????????????????????????????????????????????????????????????????????????????5????????????????????????????????????
????????????????????????????????????????????????
- ????????????????????????????????????????????????????????????????????????????????????????????????1????????????112????????????????????????????????????????????????????????????0?????????????????????112??????????????????0????????????99??????????????????????????????????????????
- ?????????????????????????????????????????????n_owned??????
- ???????????????n_owned??????1???????????????????????????????????????????????????????????????1??????????????????????????????????????????
- ???????????????n_owned??????5???????????????????????????????????????????????????????????????5???????????????????????????????????????????????????????????????4????????????
???99???112????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????n_owned??????1?????????????????????n_owned??????5????????????????????????????????????
???????????????InnoDB????????????????????????????????????????????????????????????????????????????????????????????????????????????1???????????????????????????????????????????????????????????????1~8???????????????????????????????????????????????????????????????4-8?????????????????????????????????????????????????????????
- ???????????????????????????????????????????????????????????????????????????????????????????????????????????????
- ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????n_owned??????1??????????????????????????????????????????????????????????????????????????????8??????
- ?????????????????????????????????8???????????????????????????????????????????????????????????????????????????????????????4?????????????????????5???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????page_demo??????????????????????????????????????????????????????????????????????????????????????????????????????page_demo???????????????????????????
mysql> INSERT INTO page_demo VALUES(5, 500, 'eeee'), (6, 600, 'ffff'), (7, 700, 'gggg'),
(8, 800, 'hhhh'), (9, 900, 'iiii'), (10, 1000, 'jjjj'), (11, 1100, 'kkkk'), (12, 1200, 'l
lll'), (13, 1300, 'mmmm'), (14, 1400, 'nnnn'), (15, 1500, 'oooo'), (16, 1600, 'pppp');
Query OK, 12 rows affected (0.00 sec)
Records: 12 Duplicates: 0 Warnings: 0
??????????????????????????????????????????12???????????????????????????????????????18????????????????????????????????????????????????????????????????????????5????????????????????????
?????????16?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????n_owned ??? next_record ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????? ????????????????????????4??????????????????????????? 0 ??? 1 ??? 2 ??? 3 ??? 4 ?????????????????????????????????????????? low=0 ?????????????????????high=4 ???????????????????????????????????? 6 ?????????????????????????????????
- 1?????????????????????????????? (0+4)/2=2 ??????????????? ???2 ??????????????????????????? 8 ???????????? 8 > 6 ???????????????high=2 ??? low ???????????????
- 2???????????????????????????????????? (0+2)/2=1 ??????????????? ???1 ????????????????????? 4 ???????????? 4 < 6 ???????????????low=1 ??? high ???????????????
-
3??? ?????? high - low ?????????1??????????????????????????? 5 ???????????? ???2 ?????????????????????????????????????????? ???2 ?????????????????????????????????????????????????????????????????? ???2 ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ???2 ?????????????????????????????? 8 ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ???1 ?????????????????????????????? 4 ?????????????????????????????????????????? ???2 ?????????????????????????????????????????????????????? 5 ?????????????????????????????????????????? 5 ???????????????????????????2????????????????????????????????????????????? 6 ????????????????????????????????????????????????????????????????????????1~8???????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????
1???????????????????????????????????????????????????????????????????????????????????????????????????
2??????????????????next_record????????????????????????????????????????????????
??????Page Header??????????????????
??????InnoDB?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Page Header????????????????????????????????????????????????????????????????????????56??????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????? PAGE_N_DIR_SLOTS ??? PAGE_LAST_INSERT ?????? PAGE_N_RECS ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
PAGE_DIRECTION ??? PAGE_N_DIRECTION ????????????
-
PAGE_DIRECTION
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? PAGE_DIRECTION ???
-
PAGE_N_DIRECTION
???????????????????????????????????????????????????????????? InnoDB ?????????????????????????????????????????????????????????????????????
????????? PAGE_N_DIRECTION ?????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????
??????File Header??????????????????
??????????????? Page Header ??????????????? ????????? ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? File Header ??????????????????????????????????????????????????????????????????????????? File Header ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????? 38 ????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????
-
FIL_PAGE_SPACE_OR_CHKSUM
???????????????????????????????????????checksum????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????? ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
-
FIL_PAGE_OFFSET
????????? ??? ?????????????????????????????????????????????????????????????????? InnoDB ??????????????????????????????????????? ??? ???
-
FIL_PAGE_PREV ??? FIL_PAGE_NEXT
???????????????????????? InnoDB ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? InnoDB ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? FIL_PAGE_PREV ??? FIL_PAGE_NEXT
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????? ????????????????????? FIL_PAGE_INDEX ???????????????????????????????????????????????????????????????
????????????????????????????????????
?????? File Header ?????????????????????????????????????????????????????????????????????Mysql是怎么运行的——InnoDB数据页结构一、不同类型的页简介二、数据页结构的快速浏览三、记录在页中的存储四、Page Directory(页目录)四、Page Header(页面头部)五、File Header(文件头部)六、File Trailer七、总结
??????File Trailer
???????????? InnoDB ????????????????????????????????????????????????????????????????????????????????? ??? ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? InnoDB ???????????????????????????????????????????????? File Trailer ???????????????????????? 8 ??????????????????????????????2???????????????
-
???4??????????????????????????????
?????????????????? File Header ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? File Header ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? File Header ????????????????????????????????????????????????????????? File Trialer ???????????????????????????????????????????????????????????????????????????????????????
-
???4?????????????????????????????????????????????????????????????????????LSN???
????????????????????????????????????????????????????????????????????????????????? LSN ??????????????????????????????????????????????????????????????????
????????????
- InnoDB????????????????????????????????????????????????????????????????????????????????????????????? ????????? ???
- ???????????????????????????????????????7?????????????????????File Header ????????????????????????????????????????????????38?????????
-
Page Header ??????????????????????????????????????????????????????56????????????
Infimum + Supremum ??????????????????????????????????????????????????????????????????????????????????????? 26 ????????????
- User Records ??????????????????????????????????????????????????????????????????
- Free Space ???????????????????????????????????????????????????
- Page Directory ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
- File Trailer ?????????????????????????????????????????????????????????8????????????
- ??????????????????????????????????????? next_record ?????????????????????????????????????????????????????? ????????? ???
- InnoDB ???????????????????????????????????????????????????????????????????????????????????????????????????????????? ??? ????????????Page Directory ????????????????????????????????????????????????????????????????????????????????????
- ?????????????????????????????????????????????
- ???????????????next_record???????????????????????????????????????????????????
- ?????????????????? File Header ??????????????????????????????????????????????????????????????????????????????????????? ????????? ???
-
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????? LSN ?????????????????????????????????????????? LSN ??????????????????????????????????????????????????????????????????
????????????????????
??????????????????SpringBoot????????????????????????-??????SpringBoot
??????????????????SpringBoot???????????????Web??????????????????