当前位置:网站首页>MySQL index (I)
MySQL index (I)
2022-07-19 14:40:00 【After all, Yin Jianwei】
Indexes
1、 Index Overview
Indexes (index) Help MySL Data structure for efficient data acquisition ( Orderly ). Out of data , The database system also maintains a data structure that satisfies a specific search algorithm , These data structures are referenced in some way ( Point to ) data , In this way, advanced search algorithms can be implemented on these data structures , This data structure is the index .

remarks : The above binary tree index structure is only a schematic diagram , Not a real index structure .
Advantages and disadvantages :
| advantage | Inferiority |
|---|---|
| Improve the efficiency of data retrieval , Reduce the IO cost | Index columns also take up space . |
| Sort data through index columns , Reduce the cost of sorting data , Reduce CPU Consumption of | Indexing improves query efficiency , At the same time, it also reduces the speed of updating tables , For example, row the table Insert、Update、Delete when , Low efficiency . |
2、 Index structure
Mysql Indexing is implemented at the storage engine level , Different storage engines have different structures , It mainly includes the following :
| Index structure | describe |
|---|---|
| B+Tree Indexes | The most common type of index , Most engines support B+ Tree index |
| Hash Indexes | The underlying data structure is realized by hash table , Only the exact index matches the columns , Range query is not supported |
| R-Tree( Spatial index ) | The spatial index is MyISAM A special index type of the engine , Mainly used for geospatial data types , Usually used less |
| Full-text( Full-text index ) | It's a way of building inverted indexes , How to quickly match documents . Be similar to Lucene,Solr,ES |
| Indexes | InnoDB | MyISAM | Memory |
|---|---|---|---|
| B+Tree Indexes | Support | Support | Support |
| Hash Indexes | I won't support it | I won't support it | Support |
| R-Tree Indexes | I won't support it | Support | I won't support it |
| Full-text Indexes | 5.6 Support in the future | Support | I won't support it |
What we usually call index , If not specified , Generally speaking, it means B+ Index of tree structure organization .
Disadvantages of binary tree : On sequential insertion , It will form a linked list , Query performance is greatly reduced . In case of large amount of data , Deeper levels , The retrieval speed is slow .
Red and black trees : In case of large amount of data , Deeper levels , The retrieval speed is slow .


be relative to B-Tree difference :
1、 All data will appear in the leaf node
2、 Leaf nodes form a one-way linked list

Hash Indexes :
Hash Index characteristics :
1、Hash Indexes can only be used for peer-to-peer comparisons (=,in), Range query is not supported (between,>,<,…)
2、 Cannot complete sort operation with index
3、 High query efficiency , Usually only one search is needed , Efficiency is usually higher than B+Tree Indexes
Storage engine support :
stay MySQL in , Support hash The index is Memory engine , and InnoDB It has adaptive function hash function ,hash The index is the storage engine B+Tree The index is automatically built under specified conditions .
Why? InnoDB The storage engine chooses to use B+Tree Index structure ?
- Relative to a binary tree , Fewer levels , High search efficiency ;
- about B-Tree, Whether leaf nodes or non leaf nodes , Data will be saved , This results in fewer key values stored in a page , The pointer decreases , Save a lot of data as well , Can only increase the height of the tree , Resulting in reduced performance
- relative hash Indexes ,B+Tree Support range matching and sorting operations
3、 Index classification
| classification | meaning | characteristic | keyword |
|---|---|---|---|
| primary key | The index created for the primary key in the table | Automatically created by default , There can only be one | PRIMARY |
| unique index | Avoid duplicate values in a data column in the same table | There can be multiple | UNIQUE |
| General index | Quickly locate specific data | There can be multiple | |
| Full-text index | The full-text index looks up the keywords in the text , Instead of comparing the values in the index | There can be multiple | FULLTEXT |
stay InnoDB In the storage engine , According to the storage form of the index , It can be divided into the following two types :
| classification | meaning | characteristic |
|---|---|---|
| Clustered index (Clustered Index) | Store the data in the index and put it in one piece , The leaf node of the index structure holds the row data | There has to be , And there's only one |
| Secondary indexes (Secondary Index) | Separate data from index , The leaf node of the index structure is associated with the corresponding primary key | There can be multiple |
Clustered index selection rules :
- If there is a primary key , A primary key index is a clustered index .
- If there is no primary key , The first unique index will be used (UNIQUE) As a clustered index .
- If the table does not have a primary key , Or a suitable unique index , be InnoDB It will automatically generate a rowid As a hidden clustered index .

hypothesis Query name Arm Of : select * from user where name = ‘Arm’;
He will first go to the secondary index to query the primary key id, Then query the clustered index and find id = 10 Row data , This is also called a table query .
reflection :
1、 once SQL sentence , Which is more efficient ? Why? ?
select * from user where id = 10;
select * from user where name = 'arm';
# remarks :id Primary key ,name Fields are indexed
This is very simple ,id Primary key , explain id Is clustered index , You only need to query once to get row data
And in accordance with name To query, you need to query twice , Return to the table for query
边栏推荐
- Problème de la valeur maximale de la fenêtre coulissante
- 洛谷:P4516 [JSOI2018] 潜入行动(树形dp、树上分组背包统计方案数)
- Data consistency between redis and MySQL
- 单片机软件定时器V2.0
- 优秀的jar包启动shell脚本收藏
- 歐奈爾的RPS曲線的編制方法(陶博士原創)
- Brief introduction of Bezier curve
- CF 807 E. Mark and Professor Koro(权值线段树)
- 智康护物业养老服务方案
- 2021 national vocational college skills competition network construction and application events
猜你喜欢

Huawei wireless devices are configured with static load balancing

4 a company has branches in six cities C1, C2, C3... C6. The connection between cities Ci and CJ (I, j=1,2,3,... 6) and the cost are listed in the following weighted adjacency matrix C

Configure spectrum navigation for Huawei wireless devices

滑動窗口最大值問題

Gradle introduction notes

O'Neill's RPS curve compilation method (original by Dr. Tao)

Can ping command still play like this?

Tongweb production system emergency treatment plan

Redis 与 Mysql 的数据一致性

手册不全,如何手工刨出TongWeb的監控信息?
随机推荐
函數初認識-下
Is it true that tongdaxin opens an account? Is it safe for tongdaxin to open an account?
How to avoid global index in pychart? How to cancel the indexing of a folder?
JVM性能优化
JVM performance optimization
Matplotlib draw multi line graph (solve the problem that Matplotlib Chinese cannot be displayed)
2021 年全国职业院校技能大赛 网络搭建与应用赛项
ShanDong Multi-University Training #3
坐标模拟矩阵旋转的公式
Win10 Microsoft Store cannot be opened (enable TLS 1.2)
Problème de la valeur maximale de la fenêtre coulissante
P8346 最澄澈的空与海【无向图拓扑】
Prefix equality [DP | hash]
树与二分图【思维】
【MQTT从入门到提高系列 | 06】MQTT3.1.1之SUBSCRIBE订阅工作流
慎用TongWeb的热部署功能
Initial understanding of functions - next
函数初认识-下
05--- antireflective film
AcWing 274. 移动服务【DP】