Home  >  Article  >  What is the principle of btree index

What is the principle of btree index

藏色散人
藏色散人Original
2020-07-01 09:34:264368browse

The btree index principle is that the binary tree results in a very high tree height. The nodes that are very close logically are very far away physically and cannot take advantage of locality. The number of IOs is high and the search efficiency is low; Btree is a balanced "m -way" search tree, which can use multiple branch nodes to reduce the number of nodes experienced when querying data.

What is the principle of btree index

BTree index principle

Binary tree results in very high tree height and logically close nodes. Physically very far away, locality cannot be exploited, IO times are high, and search efficiency is low

Btree is a balanced m-way search tree, which can use multiple branch nodes (subtree nodes) to reduce queries The number of nodes that data has experienced, thereby saving access time. m is called the degree of B-Tree.

The B tree can be seen as an extension of the 2-3 search tree, that is, it allows each node to have M-1 child nodes.

Features

  • There is a root node, the root node has only one record and two children or the root node is empty;

  • The key and pointer in each node record are spaced apart from each other, and the pointer points to the child node;

  • d represents the width of the tree. Except for leaf nodes, other Each node has [d/2,d-1] records, and the keys in these records are arranged by size from left to right, and there are [d/2 1,d] children;

  • In a node, all keys in the n-th subtree are less than the n-th key in this node and greater than the n-1th key;

  • All leaf nodes must be at the same level, that is, they have the same depth;

  • Due to the characteristics of B-Tree, the algorithm for retrieving data by key in B-Tree is very intuitive: First, a binary search is performed from the root node. If found, the data of the corresponding node is returned. Otherwise, the node pointed to by the pointer of the corresponding interval is searched recursively until the node is found or the null pointer is found. The former search is successful, and the latter search fails.

Recommended: "mysql tutorial"

The above is the detailed content of What is the principle of btree index. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn