当前位置:网站首页>Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
2022-07-06 13:08:00 【Geometer】
As mentioned earlier , A good index can speed up mysql Retrieval speed of , But in fact, there are different types of indexes , For example, different tools can also play a suitable effect in different application scenarios
mysql The current indexes mainly include B-TREE ,B+TREE ,HASH
1.HASH Indexes
Hash indexed key,value The format of is very suitable for indexing , For each row of data , The storage engine will calculate one hashcode,, Hash index will all hashcode Store in index , Save the pointer of each row of data at the same time
The disadvantage of hash index :
1. Hash index only contains hash value and row pointer , Do not store field values , Therefore, you cannot use the values in the index to read rows , To adopt hashcode
2.hash The index is suitable for comparing equivalent queries , For some range queries, they are not stored in the order of index values , Therefore, it is not suitable for sorting
3. A lot of hash Conflict between , The cost of maintenance operations can be high
2.B-Tree Indexes
B Tree is a balanced multi-path search tree , We call the maximum number of subtrees of nodes in the tree B The steps of the tree . It's usually written as m.
B Tree lookup operation :
B The search of a tree is actually very similar to a binary sort tree , It can be understood as m Sort tree by fork
① Let the keywords to be found first key Compare with the keywords in the node , If it is equal to a keyword , Then the search is successful .
② If it is not equal to all keywords , Then look at key In which range , Then go to the subtree pointed to by the corresponding pointer to find .
example : If Key Than the first keyword K1 Still small , Then go P0 Look in the subtree pointed to by the pointer , If it's better than the last keyword KN Also big , Then go PN Look in the subtree pointed to by the pointer .
First step : Heel node 10 Compare , Not equal but better 10 Big , Go to the subtree on the right to find ;
The second step : And keywords in the right subtree 14 Compare , Not equal but better 14 Small , So go to the left sub tree to find ;
The third step : And keywords in the left subtree 11 Compare , equal , Get its data, return .
B Operations such as inserting and deleting trees are not described in detail , You can read this post if you need it https://www.cnblogs.com/xiaofengshan/p/15443140.html
advantage :
B Trees can store keys and values at the same time in internal nodes , therefore , Putting frequently accessed data close to the root node will greatly improve the query efficiency of hot data . This characteristic makes B Trees in It is more efficient in the scenario of repeated query of specific data .
3.B+ Tree index
B+ Trees are B- A variation of a tree , It's also a multi-channel search tree . A tree m Step B+ Trees mainly have these characteristics :
Each node has at most m Little girl ;
The range of the number of non root node key values :⌈m/2⌉ - 1 <= k <= m-1
Adjacent leaf nodes are connected by pointers , And it is sorted by keyword size .
advantage :
When a full data traversal is needed ,B+ Trees only need to use O(logN) Time to find the smallest node , And then through the chain O(N) The order of traversal can be . and B Trees need to traverse every layer of the tree , This will require more memory replacements , So it takes more time
B+ Trees and B- The main differences between trees are as follows :
B- The nodes inside the tree hold the data ; and B+ The nodes inside the tree do not store data , Index only , Only its leaf node stores data .
B+ The adjacent leaf nodes of the tree are connected by linked list pointers ,B- Trees are not .
During the search ,B- The tree ends when it finds the value , and B+ The tree needs to find the data in the leaf node through the index to finish
B- Any keyword in the tree appears in only one node , and B+ Trees can appear many times .
边栏推荐
- 系统设计学习(一)Design Pastebin.com (or Bit.ly)
- 记录:下一不小心写了个递归
- 阿里云微服务(三)Sentinel开源流控熔断降级组件
- One article to get UDP and TCP high-frequency interview questions!
- Redis介绍与使用
- On March 15, the official version of go 1.18 was released to learn about the latest features and usage
- [algorithm] sword finger offer2 golang interview question 6: sum of two numbers in the sorting array
- [algorithm] sword finger offer2 golang interview question 10: subarray with sum K
- 10 minutes pour maîtriser complètement la rupture du cache, la pénétration du cache, l'avalanche du cache
- Introduction pointer notes
猜你喜欢
![[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers](/img/64/0f352232359c7d44f12b20a64c7bb4.png)
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers

Novatel board oem617d configuration step record

如何保障 MySQL 和 Redis 的数据一致性?

十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩

使用rtknavi进行RT-PPP测试
![[算法] 劍指offer2 golang 面試題2:二進制加法](/img/c2/6f6c3bd4d70252ba73addad6a3a9c1.png)
[算法] 劍指offer2 golang 面試題2:二進制加法

【无标题】

国企秋招经验总结

Dark chain lock (lca+ difference on tree)

系统设计学习(一)Design Pastebin.com (or Bit.ly)
随机推荐
Answer to "software testing" exercise: Chapter 1
[untitled]
XV Function definition and call
PRIDE-PPPAR源码解析
TYUT太原理工大学2022“mao gai”必背
[algorithm] sword finger offer2 golang interview question 2: binary addition
GPS高程拟合抗差中误差的求取代码实现
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
MySQL shutdown is slow
GNSS positioning accuracy index calculation
Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
记录:动态Web项目servlet访问数据库404错误之解决
Several high-frequency JVM interview questions
[rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
Code example of MATLAB reading GNSS observation value o file
TYUT太原理工大学2022数据库题库选择题总结
Wechat applet development experience
[Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
编辑距离(多源BFS)
RTKLIB: demo5 b34f.1 vs b33