Algorithm comparison
Binary tree
When I look for 8 Five steps are needed
Red and black Tree
When I query 8 It takes four times when there are some optimizations relative to the binary tree without infinite extension. The depth of the red-black tree will be very deep (the depth is not controllable)
hash
If the amount of data is large
Quick query (cannot find range)
BTree
The query can be found only by checking two steps, the shortcomings are carried (data) Expand the horizontal and reduce the vertical depth
ps: java fetches data generally like this: java program–>CPU—>memory—->hard disk, and the interaction between memory and hard disk There is a size limit, it is a page of data 4 It is about k, so it is not possible to get all the data in one node. Generally speaking, the node will try to pre-store 4K capacity.
B+Tree
Why should Mysql choose B+Tree
ps:data is not placed in non-leaf nodes to increase the degree (small nodes). Generally, there will be more than one hundred so that the depth is 3~5, thereby reducing the number of queries. In addition, there will be pointers between the leaf nodes, and the data will be incremented. This allows us to search through the range of pointers, instead of searching from the top nodes one by one. It not only reduces the number of queries, but also provides range queries.