当前位置:网站首页>【mysql学习笔记22】索引
【mysql学习笔记22】索引
2022-06-25 09:32:00 【yqs_281876918】
优缺点
优势 | 劣势 |
---|---|
提高数据检索效率,降低数据库的io成本 | 索引列需要占用空间 |
通过对索引列对数据进行排序,降低数据排序的成本,降低CPU的消耗 | 索引大大提高了查询效率,同时也降低了更新表的效率,因为更新表的同时也需要更新索引 |
索引结构
索引结构 | 描述 |
---|---|
B+Tree索引(默认) | 最常见的索引类型,大部分引擎都支持 |
Hash索引 | 底层原理是哈希表,不支持范围查询,只能够精确匹配 |
R-Tree | 常用于地理空间数据类型 |
Full-text(全文索引) | 是一种通过建立倒排索引,快速匹配文档的方式 |
各引擎对索引的支持
索引分类
分类 | 含义 | 特点 | 关键字 |
---|---|---|---|
主键索引 | 针对于表中主键创建的索引 | 默认自动创建,只能有一个 | PRIMARY |
唯一索引 | 避免一个列有重复值 | 可以有多个 | UNIQUE,可以在建表的时候就指定,也可以后期手动添加 |
常规索引 | 快速定位数据 | 可以有多个 | 无,需手动创建 |
全文索引 | 快速进行文本检索 | 可以有多个 | FULLTEXT |
拓展:列值唯一就是依靠唯一索引实现的。
分类 | 含义 | 特点 |
---|---|---|
聚集索引 | 将数据存储与所以放到一块,索引结构的叶子节点保存了行数据 | 必须有,且只有一个,创建表时会自动将主键作为聚集索引,如果没有主键,使用第一个唯一索引作为聚集索引,如果都没有,InnoDB会自动一个隐藏的rowid作为聚集索引 |
二级索引 | 将数据与索引分开存储,索引结构的叶子节点存的是对应的主键 | 可以存在多个 |
实例
比如执行select * from user where name =‘Arm’;
那么就会先去name索引里面检索Arm,查询到Arm里面对应的id是10,那么就会拿着这个10去聚集索引里面查找具体数据,然后返回。这个过程叫做“回表查询”。
创建索引
create [unique|fulltext] index index_name on table_name (index_col_name1,…);
查看索引
show index from table_name;
删除索引
drop index index_name on table_name;
边栏推荐
- Specific usage of sklearn polynomialfeatures
- 3、 Automatically terminate training
- Flutter multilingual intl: ^0.17.0 cannot be imported
- [competition - Rural Revitalization] experience sharing of Zhejiang Rural Revitalization creative competition
- 股票在线开户安全吗?找谁可以办理?
- C#启动程序传递参数丢失双引号,如何解决?
- 《乔布斯传》英文原著重点词汇笔记(三)【 chapter one】
- 从别人库里拷贝的游戏如何再自己的库里显示
- 106. simple chat room 9: use socket to transfer audio
- Close a thread
猜你喜欢
[zufe expense reimbursement] zhecai invoice reimbursement specification (taking Xinmiao reimbursement as an example), which can be passed in one trip at most
On the underlying index principle of MySQL
Explanation of assertions in JMeter
Compare and explain common i/o models
【期末复习笔记】数字逻辑
《JVM》对象内存分配的TLAB机制与G1中的TLAB流程
Analysis on the bottom calling process of micro service calling component ribbon
compiling stm32f4xx_it.c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
Title B of the certification cup of the pistar cluster in the Ibagu catalog
2022 meisai question a idea sharing
随机推荐
jmeter中csv参数化
2021mathorcupc topic optimal design of heat dissipation for submarine data center
socket编程——epoll模型
Matplotlib plt grid()
请问在手机上开户股票,还是去证券公司开户安全?
Is it safe for Huatai Securities to open a stock account on it?
微服务调用组件Ribbon底层调用流程分析
一、单个神经元网络构建
Level 6 easy to mix words
annotation lib 和 processor lib如何引用
CSV parameterization in JMeter
Use Navicat to compare data differences and structure differences of multi environment databases, and automatic DML and DDL scripts
5、 Project practice --- identifying man and horse
Mapping mode of cache
(translation) the use of letter spacing to improve the readability of all capital text
[opencv] - input and output XML and yaml files
Make a skylearn high-dimensional dataset_ Circles and make_ moons
compiling stm32f4xx_it.c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
neo4jDesktop(neo4j桌面版)配置自动启动(开机自启)
How can games copied from other people's libraries be displayed in their own libraries