当前位置:网站首页>MySQL index types B-tree and hash
MySQL index types B-tree and hash
2022-07-03 08:40:00 【Programmer small circle】
Hash The particularity of index structure , Its retrieval efficiency is very high , The index can be retrieved at one time , Unlike B-Tree The index needs to be from the root node to the branch node , Finally, you can access the page node for many times IO visit , therefore Hash The query efficiency of index is much higher than B-Tree Indexes .
Maybe a lot of people have questions again , since Hash Index is more efficient than B-Tree Much higher , Why don't everyone use Hash Index and use B-Tree Index? ? Everything has two sides ,Hash The index is the same , although Hash Index efficiency is high , however Hash Because of its particularity, the index itself also brings a lot of Limitations and drawbacks , There are mainly the following .
1).Hash Index can only satisfy "=","IN" and "<=>" Inquire about , Can't use range query .
because Hash Index comparison is to carry out Hash After the operation Hash value , So it can only be used for equivalent filtering , Can't be used for range based filtering , Because after the corresponding Hash After algorithm processing Hash The relationship between the size of the value , There's no guarantee of and Hash It's exactly the same before the operation .
2).Hash Index can't be used to avoid sorting data .
because Hash What the index stores is the process Hash After calculation Hash value , and Hash The magnitude of the value does not necessarily relate to Hash The key value before the operation is exactly the same , So the database can't use the index data to avoid any sort operation ;
3).Hash Index can't query with partial key .
For composite indexes ,Hash The index is calculating Hash When the value is combined, the index key is combined and then calculated together Hash value , Not separately Hash value , So when you query by combining one or more index keys in front of the index ,Hash Index can't be used .
4).Hash Index can't avoid table scanning at any time .
I already know that ,Hash Index is to pass the index key through Hash After the operation , take Hash The result of the calculation Hash The value and the corresponding row pointer information are stored in a Hash In the table , Because different index keys are the same Hash value ( Hash Collisions ), So even if you meet someone Hash Number of records of key value data , I can't go from Hash Direct query in index , You still need to access the actual data in the table for corresponding comparison , And get the corresponding result .
5).Hash Index encountered a lot of Hash When the values are equal, the performance is not necessarily better than B-Tree High index .
For index keys with low selectivity , If you create Hash Indexes , Then there will be a lot of record pointer information stored in the same Hash Correlation of values . In this way, it will be very troublesome to locate a record , Will waste many times table data access , And the overall performance is low
In short , Hash index is to use a certain hash algorithm , Convert the key value to a new hash value , You don't need to search like B+ The tree searches from root node to leaf node step by step , Only one hash algorithm is needed to locate the corresponding location immediately , Very fast .
B+ Obvious differences between tree index and hash index difference yes :
1). If it is equivalent query , So hash index has an absolute advantage , Because it only needs to go through the algorithm once to find the corresponding key value ; Yes, of course , The premise is , Key values are unique . If the key value is not unique , You need to find the key first , Then scan back according to the list , Until we find the corresponding data ;
2). You can also see from the diagram , If it's range search , At this time, hash index is useless , Because it used to be an ordered key , After hash algorithm , It could become a discontinuity , There is no way to use the index to complete the range query ;
3). Empathy , Hash index also can't use index to complete sorting , as well as like ‘xxx%’ Such a partial fuzzy query ( This kind of partial fuzzy query , In fact, it is also range query in essence );
4). Hash index also does not support multi column joint index The leftmost matching rule ;
5).B+ The key search efficiency of tree index is average , Unlike B Trees fluctuate so much , In the case of a large number of duplicate key values , The efficiency of hash index is also very low , Because of the so-called hash collision problem .
边栏推荐
- 【Rust 笔记】13-迭代器(上)
- Intersectionpicker in osgearth
- producer consumer problem
- Simply start with the essence and principle of SOM neural network
- Unity editor expansion - draw lines
- Cesium service deployment, and import and display local 3dfiles data
- Delete the last character of the string in golang
- Golang's range
- Graphics_ Learnopongl learning notes
- Constraintlayout's constraintset dynamically modifies constraints
猜你喜欢

VIM learning notes from introduction to silk skating

单调栈-42. 接雨水

图像处理8-CNN图像分类

Advanced OSG collision detection

梯度下降法求解BP神经网络的简单Demo

22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令

Monotonic stack -42 Connect rainwater
![[updating] wechat applet learning notes_ three](/img/05/958b8d62d3a42b38ca1a2d8631a7f8.png)
[updating] wechat applet learning notes_ three

Markdown learning

matlab神经网络所有传递函数(激活函数)公式详解
随机推荐
[concurrent programming] Table hopping and blocking queue
Osgearth starry background
Kwai 20200412 recruitment
Talking about: is the HashSet set ordered or disordered /hashset set unique, why can we store elements with the same content
[concurrent programming] atomic operation CAS
Simply start with the essence and principle of SOM neural network
[concurrent programming] consistency hash
Markdown directory generation
Vscode, idea, VIM development tool shortcut keys
【Rust 笔记】07-结构体
Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
Redis data structure
Jupyter remote server configuration and server startup
Explain sizeof, strlen, pointer, array and other combination questions in detail
Annotations simplify configuration and loading at startup
Use of ue5 QRcode plug-in
producer consumer problem
Student educational administration management system of C # curriculum design
Location of package cache downloaded by unity packagemanager
[MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle