Principle b + tree

Indexes to improve query efficiency principle: reduce disk the IO
InnoDB engine index as to the B + tree is stored:
. 1, B + tree is more balanced trees, up to open m forks (m> = 2), except for the root of each of node contains a minimum of elements up to element m th element, m we call tree order b, B + tree containing multi-stage containing reason, by reducing the height of the tree to maximize the number of child nodes within each internal node, because the higher the depth of the tree, the slower the query speed, B + tree does not require regular rebalancing like other self-balancing binary search tree.
2, the height difference of the tree balanced tree tree 1 or less, more uniform, will not be branches of a particularly great depth.
3, B + Tree made small based on the transformation of B-Tree data structure, each Leaf Node above the relevant information is stored the index key, but also after the point is stored adjacent to the Leaf Node a LeafNode pointer information, mainly in order to speed up the retrieval of a plurality of adjacent Leaf Node efficiency considerations.
4, B-Tree structures can be seen in FIG key values in each node contains not only data, and data values. Each of the memory page is limited, if the data will result in large data for each node (i.e., a page) can store a small number of key, when a large amount of data stored will also lead to B- Tree of greater depth, increasing the disk when I query / O times, thereby affecting the query efficiency. In the B + Tree, all the nodes are in accordance with the key-data records stored in the order of the leaf nodes of the same level, not only stores the key value of the leaf node information, which can greatly increase the number of key values stored at each node reduced height + Tree B.
B + Tree index database can be divided into clustered index (clustered index) and secondary indexes (secondary index). B + Tree achieve the above example in FIG database index is the aggregate, the aggregate index B + Tree of leaf nodes is stored in the data rows of the entire table. The index difference between the auxiliary leaf nodes clustered index is a secondary index that does not contain all the data of the rows, but is stored the data clustered index key corresponding row, i.e., the primary key. When to query the data through secondary indexes, InnoDB storage engine will traverse the secondary index to find the primary key, and then find a complete line of data recorded by the primary key clustered index.

Process b + tree index
lookup
to find in a typical manner, similar to a binary search tree. Starting at the root node, the tree top-down traversal, selecting separated child pointer value to find a value of either side. In a typical internal node binary search is used to determine the position.
Insert
a node to be in violation state, it must contain the number of elements outside an acceptable range.
1. First, look where you want to insert the node's position. Then the value of the inserted node.
2. If there is no node is in violation state, the process ends.
3. If a node has too many elements, put it split into two nodes, each with a minimum number of elements. Recursive up in the trees to continue this process until you reach the root, if root node is split, create a new root node. To make it work, the minimum and maximum number of elements typically must be chosen to minimize the number of not less than half the maximum number.
Delete
1. First, find the value you want to delete. This value is then deleted from the node in which it is contained.
2. If there is no node is in violation state, the process ends.
3. If the node is in violation of the state there are two possible scenarios:

More technical advice may be concerned about: gzitcast

Guess you like

Origin www.cnblogs.com/heimaguangzhou/p/11511783.html