Database B tree B + tree, database B tree

Source: Internet
Author: User

Database B tree B + tree, database B tree

In database indexes, B or B + trees are generally used for retrieval and query.

The following describes how to query data in two data structures:


1) B tree

B treeEach nodeData Object Storage address pointer that contains key-value and key-value pairs,Therefore, you can search for an object without reaching the leaf node of the tree..

A successful search includes a search in a node and a search along a specific path. The time for a successful search depends on the level of the key code and the number of key codes in the node.

  The method to search for a given keyword in Tree B is: first obtain the root node, the key word K1,…, contained in the root node ,..., Kj searches for the given keywords (available sequential search or binary search). If the keyword is found to be equal to the given value, the search is successful. Otherwise, you must be sure that the keyword to be queried is between a certain Ki Or Ki + 1, so take the index node block of the next layer referred to by Pi to continue searching until it is found, or if the pointer Pi is null, the query fails.

  

2) B + tree

The key code stored in the non-leaf node of the B + tree does not indicate the address pointer of the data object., Non-leaf nodes are only part of the index. All leaf nodes on the same layer contain all the key codes and the corresponding data object storage address pointer.And Leaf nodes are connected in ascending order by key code. If the actual data objects are stored in the order they are added instead of the key code count, the leaf node index must be a dense index. If the actual data storage is stored in the key code order, sparse indexes are used for leaf node indexes.

The B + tree has two head pointers. One is the root node of the tree and the other is the leaf node with the minimum key code.

Therefore, the B + tree has two search methods:

One is to search by the linked list pulled by the leaf node.

One is to start searching from the root node, which is similar to tree B,However, if the key code of a non-leaf node is equal to the given value, the search will not stop, but will continue along the right pointer and keep checking the key code on the leaf node. Therefore, no matter whether the search is successful or not, all layers of the tree are completed.

In the B + tree, data objects are inserted and deleted only on leaf nodes.

The data structures of these two indexes are different:


The same key value in tree a and Tree B does not appear multiple times, and it may appear in leaf nodes or non-leaf nodes. The keys of the B + tree will certainly appear in the leaf node, and may also appear repeatedly in non-leaf nodes to maintain the balance of the B + tree.

B. Because the key position of Tree B is not fixed and appears only once in the entire tree structure, although it can save storage space, it significantly increases the complexity of insert and delete operations. B + tree is a good compromise.

The query efficiency of the c and B trees is related to the key position in the tree. The maximum time complexity is the same as that of the B + tree (when the leaf node is used ), the minimum time complexity is 1 (at the root node ). The complexity of the B + tree is fixed for a constructed tree.


For more information about the B, B +, B-, and B * trees, see

Http://www.cnblogs.com/oldhorse/archive/2009/11/16/1604009.html


B tree: Binary Tree. Each node stores only one keyword. If it is equal to or equal to, it hits. If it is less than or equal to the left node, it is greater

Go to the right node;


B-tree: multi-path search tree. Each node stores M/2 to M keywords. Non-leaf node storage points to the key.

Subnode of the word range;

All keywords appear in the entire tree only once, and can be hit by non-leaf nodes;


B + tree: adds a linked list pointer to the leaf node on the basis of B-tree. All the keywords are on the leaf node.

The non-leaf node is used as the index of the leaf node. The B + tree always hits the leaf node;


B * tree: On the basis of the B + tree, the linked list pointer is also added for non-leaf nodes, and the lowest utilization rate of nodes is added to the non-root and non-leaf nodes of the B + tree.

From 1/2 to 2/3;



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.