当前位置:网站首页>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 .
边栏推荐
- [算法] 剑指offer2 golang 面试题2:二进制加法
- [algorithm] sword finger offer2 golang interview question 5: maximum product of word length
- Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
- TYUT太原理工大学2022数据库大题之分解关系模式
- 异常:IOException:Stream Closed
- TYUT太原理工大学2022数据库题库选择题总结
- [算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
- 记录:动态Web项目servlet访问数据库404错误之解决
- isEmpty 和 isBlank 的用法区别
- TYUT太原理工大学2022软工导论大题汇总
猜你喜欢
2022国赛Re1 baby_tree
系统设计学习(三)Design Amazon‘s sales rank by category feature
抽象类和接口
[algorithm] sword finger offer2 golang interview question 10: subarray with sum K
How do architects draw system architecture blueprints?
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
121 distributed interview questions and answers
Detailed explanation of balanced binary tree is easy to understand
Fundamentals of UD decomposition of KF UD decomposition [1]
如何保障 MySQL 和 Redis 的数据一致性?
随机推荐
[untitled]
Introduction pointer notes
Record: solution of 404 error of servlet accessing database in dynamic web project
Experience summary of autumn recruitment of state-owned enterprises
Interview Essentials: talk about the various implementations of distributed locks!
阿里云微服务(二) 分布式服务配置中心以及Nacos的使用场景及实现介绍
Realization of the code for calculating the mean square error of GPS Height Fitting
3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法
一文搞定 UDP 和 TCP 高频面试题!
编辑距离(多源BFS)
Knowledge system of digital IT practitioners | software development methods -- agile
【GNSS】抗差估计(稳健估计)原理及程序实现
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
Iterable、Collection、List 的常见方法签名以及含义
Answer to "software testing" exercise: Chapter 1
如何保障 MySQL 和 Redis 的数据一致性?
[algorithm] sword finger offer2 golang interview question 7: 3 numbers with 0 in the array
XV Function definition and call
Lean product development - Lean Software Development & lean product development
Sharing ideas of on-chip transplantation based on rtklib source code