Relearn Mysql database 4: Mysql index principle and the relevant data structure algorithms

BTree

A B-tree of order m satisfy the following conditions:

1. Each node has at most m subtrees;

2. The root node has two sub-tree (in the presence of sub-tree) at least, there is at least one root keyword;

3. In addition to the root, each of the remaining branch node has at least m / 2 subtree;

4. All the leaf nodes are on the same layer, the B-tree leaf node may be seen as an external node, it does not contain any information;

5. There k subtrees branching nodes k-1 key code exists, the key codes are arranged in ascending order;

6. The number of keywords need to satisfy ceil (m / 2) -1 <= n <= m-1;
Here Insert Picture Description
Here Insert Picture Description

Insertion, deletion process

B+Tree

Feature

1, less hierarchical B + tree: B compared to B + tree for each keyword number of non-leaf nodes store more, less hierarchical tree so the query data faster;

2, B + tree query speed is more stable: B + key all data addresses are present on the leaf node, so the number of times once for each are the same so the query speed is more stable than B-tree;

3, B + tree has a natural sorting: B + tree all the leaves node data constitute an ordered list, the size of the data in the query interval, when more convenient, compact data is high, the cache hit rate will be higher than the B-tree.

4, B + tree node to traverse the whole Faster: B + tree traverse the entire tree need only to traverse all the leaf nodes without the need to ,, like B-tree, like the need to traverse each layer, which is conducive to the database to do a full table scan .

B-tree relative advantages of B + tree is, if frequently accessed data from close to the root, while non-leaf nodes of the tree itself there keyword B address their data, so that data retrieval time will be better than B + tree fast.

Here Insert Picture Description
Here Insert Picture Description

innoDB的B+Tree

Here Insert Picture Description

Reference documents:
a balanced binary tree, B tree, B + tree, B * tree understand one of you all understand

article

mind Mapping

Published 81 original articles · won praise 19 · views 3607

Guess you like

Origin blog.csdn.net/c22cxz/article/details/104913846