Comparison of the advantages and disadvantages of B-tree, B + Tree and b* tree

Source: Internet
Author: User
Tags mongodb postgresql
First Note: The B-Tree is a C-tree, "-" is a ligature symbol, not a minus sign.
B-Tree is a Balance The Multi-way lookup (also called sort) Tree, which is applied in the file system. Used primarily as an index for a file. where B means balance (Balance)

B + trees have one of the greatest benefits, convenient sweep of the library, B. Tree must use the method of sequence traversal in order to sweep the library, and B + trees sweep directly from the leaf knot.

B + Tree support for range-query (interval query) is very convenient, while the B. Tree does not support。 This is the main reason why the database chooses the B + tree.

For example, to check between 5-10, B + Tree one to 5 of this marker, and then to 10, and then strung together on the line, a tree is very troublesome. The benefit of B-trees is that successful queries are particularly advantageous because the height of the tree is generally higher than that of a B + tree. In the case of unsuccessful, B-trees are a little bit less expensive than a plus + tree.

The advantage of B-tree is that when you're looking for a value that is just a non-leaf node, finding the node succeeds and ends the query, while the B + tree is only indexed because the NON-LEAF nodes contain only the largest (or smallest) keywords in its subtree, and the lookup does not terminate when the keyword on the non-terminal node equals the point value. Instead, continue down until the leaf node. Therefore, in the B + tree, whether the search succeeds or not, is a path from root to leaf node.
There are many based on the frequency of search is the use of B-tree, the more frequent query node more toward the root, the premise is that query to do statistics, but also to do some changes to key.
In addition, B-tree is good, the root or a few layers because of query repeatedly, so these pieces of basic in memory, will not appear read disk IO, generally started, will be actively swapped into memory. MySQL's underlying storage is implemented with a B + tree, because in-memory B + trees have no advantage, but as soon as they get to disk, the power of a B + tree comes out.


b* Tree is a variant of a B + tree that adds a pointer to a sibling at the non root and non leaf nodes of a B + tree .The b* tree defines the number of non leaf node keywords at least (2/3) *m, that is, the minimum use rate of blocks is 2/3 (instead of 1/2 of B + trees);
B + Tree splitting: When a node is full, assign a new node, the data of 1/2 in the original node is copied to the new node, and then the pointer to the new node is added to the parent node. B + The division of the tree only affects the original node and the parent node, and does not affect the sibling node, so it does not need to point to the sibling pointer;
The division of the b* tree: When a knot is full, if its next sibling knot is not full, then move a subset of the data to the sibling node, insert the keyword at the original node, and finally modify the key of the sibling node in the parent node (because the sibling node's keyword range has changed); If the brothers are full, Then the new node is added between the original node and the sibling node, and the data of 1/3 is copied to the new node, and the pointer of the new node is added at the parent node.
Therefore, the probability that the b* tree allocates new nodes is lower than that of B + trees, and the space usage is higher.

Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

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.