当前位置:网站首页>【MySQL】索引的分类
【MySQL】索引的分类
2022-07-01 21:45:00 【张艳伟_Laura】
浅浅的了解一下索引的各种分类以及索引是如何创建和删除的。
【正文】
一、索引的分类
MySQL的索引包括普通索引、唯一性索引、全文索引、单列索引、多列索引和空间索引等。
● 从功能逻辑上说,索引主要有 4 种,分别是普通索引、唯一索引、主键索引、全文索引。
● 按照物理实现方式,索引可以分为 2 种:聚簇索引和非聚簇索引。
● 按照作用字段个数进行划分,分成单列索引和联合索引。
1. 普通索引
在创建普通索引时,不附加任何限制条件,只是用来提高查询效率。这类索引可以创建在任何数据类型中,其值是否唯一和非空,要由字段本身的完整性约束条件决定。建立索引后,可以通过索引进行查询,例如,在表student的字段name上建立一个普通索引,查询记录时就可以根据该索引进行查询。
2. 唯一性索引
使用UNIQUE参数可以设置索引为唯一性索引,在创建唯一性索引时,限制该索引的值必须是唯一的,但允许有空值,在一张数据表里可以有多个唯一索引。
3. 主键索引
主键索引就是一种特殊的唯一性索引,在唯一索引的基础上增加了不为空的约束,也就是NOT NULL+UNIQUE 一张表里最多只有一个主键索引
为什么,这是由主键索引的物理实现方式决定的,因为数据存储在文件中只能按照一种顺序进行存储。
4. 单列索引
在表中的单个字段上创建索引,单列索引只根据该字段进行索引,单列索引可以是普通索引,也可以是唯一性索引,还可以是全文索引,主要保证该索引只对应一个字段即可,一个表可以有多个单列索引。
5. 多列(组合、联合)索引
多列索引是在表的多个字段组合上创建一个索引。该索引指向创建时对应的多个字段,可以通过这几个字段进行查询,但是只有查询条件中使用了这些字段中的第一个字段时才会使用。
例如:在表中的字段Id name和gender上建立一个多列索引 idx_id_name_gender,只有在查询条件中使用了字段Id时该索引才会被使用,使用组合索引时遵循最左前缀集合。
6. 全文索引

7. 补充:空间索引
小结:不同的存储引擎支持的索引类型也不一样 :
InnoDB :支持 B-tree、Full-text 等索引,不支持 Hash索引;
MyISAM : 支持 B-tree、Full-text 等索引,不支持 Hash 索引;
Memory :支持 B-tree、Hash 等索引,不支持 Full-text 索引;
NDB :支持 Hash 索引,不支持 B-tree、Full-text 等索引;
Archive :不支持 B-tree、Hash、Full-text 等索引;
边栏推荐
- Business visualization - make your flowchart'run'up
- 函数基本学习之一
- A debugging to understand the slot mechanism of redis cluster
- Several ways of writing main function in C
- 详解Volatile关键字
- [live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
- 从零开始学 MySQL —数据库和数据表操作
- 工控设备安全加密的意义和措施
- 【单体】流辰信息I-BPSv3服务器推荐配置
- Which securities company should we choose to open an account for flush stock? Is it safe to open an account with a mobile phone?
猜你喜欢

Basic operation of binary tree

Manually implement function isinstanceof (child, parent)

按照功能对Boost库进行分类

MySQL learning notes - SQL optimization of optimization

函数基本学习之一
![[deep learning] use deep learning to monitor your girlfriend's wechat chat?](/img/03/ecf50eacc91c0633b0d9689cdad2c2.png)
[deep learning] use deep learning to monitor your girlfriend's wechat chat?

News classification based on LSTM model

Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue
![[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial](/img/ac/655fd534ef7ab9d991d8fe1c884853.png)
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial

MySQL之MHA高可用配置及故障切换
随机推荐
Internet of things RFID, etc
【生态伙伴】鲲鹏系统工程师培训
Sonic云真机学习总结6 - 1.4.1服务端、agent端部署
mysql 学习笔记-优化之SQL优化
String type conversion BigDecimal, date type
The difference between NiO and traditional IO
Airserver mobile phone third-party screen projection computer software
【MySQL】数据库优化方法
Clean up system cache and free memory under Linux
Separate the letters and numbers in the string so that the letters come first and the array comes last
【juc学习之路第8天】Condition
MQ学习笔记
Unity uses SQLite
基于LSTM模型实现新闻分类
游览器打开摄像头案例
Basic operation of binary tree
pytest合集(2)— pytest运行方式
详解ThreadLocal
ICML2022 | 基于元语义正则化的介入性对比学习
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan