What is the advantage of B+Tree as a Mysql index?

The nature of B+Tree:

  • Non-leaf nodes only store key-value information. (Can store more indexes)
  • There is a chain pointer between all leaf nodes. (Improve the efficiency of regional access)
  • Data records are stored in leaf nodes. (Find data faster)

1. Non-leaf nodes only store key-value information-Mysql's InnoDB storage engine only needs 3 disk IO operations at most to find a row of records (1 billion pieces of data)

The size of the page in the InnoDB storage engine is 16KB, the primary key type of the general table is INT (occupies 4 bytes) or BIGINT (occupies 8 bytes), and the pointer type is generally 4 or 8 bytes, that is, one The page (a node in the B+Tree) stores approximately 16KB/(8B+8B)=1K key values ​​(because it is an estimate, for the convenience of calculation, the value of K here is 〖10〗^3). In other words, a B+Tree index with a depth of 3 can maintain 10^3 * 10^3 * 10^3 = 1 billion records.

2. There are two-way pointers between all leaf nodes-improve the ability of Mysql to search sequentially

Compared with B-Tree, only one node can be traversed in order, but for hash indexes, it cannot support range query. B+Tree can search through two-way pointers between nodes.

3. All the data is stored in the leaf nodes and the data can be obtained directly, which reduces the number of IOs and improves efficiency

Guess you like

Origin blog.csdn.net/a1_HelloWord/article/details/104340024
Recommended