当前位置:网站首页>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 .
边栏推荐
- 2022 National Games RE1 baby_ tree
- PRIDE-PPPAR源码解析
- Lean product development - Lean Software Development & lean product development
- 十分鐘徹底掌握緩存擊穿、緩存穿透、緩存雪崩
- [算法] 剑指offer2 golang 面试题7:数组中和为0的3个数字
- 系统设计学习(一)Design Pastebin.com (or Bit.ly)
- Itext 7 生成PDF总结
- The earth revolves around the sun
- Answer to "software testing" exercise: Chapter 1
- [rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
猜你喜欢
String类
Role movement in the first person perspective
阿里云微服务(四) Service Mesh综述以及实例Istio
图书管理系统小练习
Detailed explanation of balanced binary tree is easy to understand
How to ensure data consistency between MySQL and redis?
121 distributed interview questions and answers
[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K
染色法判定二分图
[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity
随机推荐
Implementation of Excel import and export functions
Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client
错误:排序与角标越界
[algorithm] sword finger offer2 golang interview question 1: integer division
记录:Navicat Premium初次无法连接数据库MySQL之解决
[算法] 劍指offer2 golang 面試題2:二進制加法
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
2022 National Games RE1 baby_ tree
KF UD decomposition pseudo code implementation advanced [2]
One article to get UDP and TCP high-frequency interview questions!
Fairygui bar subfamily (scroll bar, slider, progress bar)
All in one 1405: sum and product of prime numbers
【rtklib】在rtk下使用抗差自适应卡尔曼滤波初步实践
平衡二叉树详解 通俗易懂
TYUT太原理工大学2022数据库大题之概念模型设计
继承和多态(下)
Sharing ideas of on-chip transplantation based on rtklib source code