温故而知新 可以为师矣
(想自学习编程的小伙伴请搜索圈T社区,更多行业相关资讯更有行业相关免费视频教程。完全免费哦!)
一、存储模型
MySQL
Each tablespace consists of database pages with a default size of 16KB. The pages are grouped into extents of size 1MB (64 consecutive pages). The “files” inside a tablespace are called segments in InnoDB.
Two segments are allocated for each index in InnoDB. One is for nonleaf nodes of the B-tree, the other is for the leaf nodes. Keeping the leaf nodes contiguous on disk enables better sequential I/O operations, because these leaf nodes contain the actual table data.
- 表空间Tablespace(ibd文件)
- 段Segment(一个索引2个段)
- 区Extent(1MB):64个Page
- 页Page(16KB):磁盘管理的最小单位
从示意图可以清晰的了解到MySQL的行数据Row都是存储到数据页Page上,每个数据页的大小为16KB。然后64个数据页进而组成一个区Extent,区又是段segment组成元素,一个索引拥有两个段,其中leaf node seagmen
t存储着逻辑上的行数据(主键索引),非主键索引存储的是主键ID。
InnoDB使用了B+树的索引模型。B+树为了维护索引的有序性,在插入新值的时候需要做必须的维护。如果在表尾插入,只需在记录后面增加,要是增加的行在表中间,就需要挪动位置给插入的行腾出空间。更糟糕的是带插入的数据页Page已经满了16KB,这时需要新申请一个新的数