磁盘扇区、文件系统、InnoDB存储引擎都有各自的最小存储单元。
show global variables like 'innodb_page_size';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| innodb_page_size | 16384 |
+------------------+-------+
1 row in set (0.00 sec)
Mysql 一页的大小为16K
Understanding B+tree Indexes and how they Impact Performance
Consider InnoDB whose page size is 16KB and suppose we have an index on a integer column of size 4bytes, so a node can contain at most 16 * 1024 / 4 = 4096 keys, and a node can have at most 4097 children.
So for a B+tree of height 1, the root node has 4096 keys and the nodes at height 1 (the leaf nodes) have 4096 * 4097 = 16781312 key values.
This goes to show the effectiveness of a B+tree index, more than 16 million key values can be stored in a B+tree of height 1 and every key value can be accessed in exactly 2 lookups.
How important is the size of the index values?
As can be seen from the above example, the size of the index values plays a very important role for the following reasons:
- The longer the index, the less number of values that can fit in a node, and hence the more the height of the B+tree.
- The more the height of the tree, the more disk accesses are needed.
- The more the disk accesses the less the performance.
So the size of the index values have a direct bearing on performance!I hope you have understood how B+tree indexes work and how they are used to improve the performance of lookups. I hope you have also understood how important it is to keep the height of the B+tree smaller so as to reduce the number of disk accesses.
主键id,我们采用bigint,8字节
一条数据大小1KB
对于MySQL,1亿行将有一个大约4层深的B + Tree