当前位置:网站首页>mysql索引
mysql索引
2022-06-13 02:43:00 【Cold Snowflakes】
约束:保证数据完整性。
索引:快速定位特定数据,提高查询效率。
实际上两个不同的概念,索引相当于在字典中建立了一个目录。
在 MySQL 中,通常有两种方式访问数据库表的行数据:
1)顺序访问
顺序访问是全表扫描,从头到尾逐行遍历,直到找到符合条件的目标数据。
在几千万条数据中查找少量的数据时,使用顺序访问方式将会遍历所有的数据,花费大量的时间,显然影响数据库的处理性能。
2)索引访问
索引访问是通过遍历索引来直接访问表中记录行。
前提是对表建立一个索引,在列上创建了索引之后,查找数据时直接根据该列上的索引找到对应记录行的位置,从而快捷地查找到数据。索引存储了指定列数据值的指针,根据指定的排序顺序对这些指针排序。
例如,在学生表 tb_students 中,如果基于 student_id 列建立了索引,系统就建立了一张索引列到实际记录的映射表。当用户需要查找 where student_id = 12022 的数据的时候,系统先在 student_id 索引上找到该记录,然后通过映射表直接找到数据行,并且返回该行数据。就像字典里的目录一样。
因为扫描索引的速度一般远远大于扫描实际数据行的速度,所以采用索引的方式可以大大提高数据库的工作效率。
索引
索引是定义在列上的。
如果作为搜索条件的列上已经创建了索引,MySQL无需扫描任何记录即可迅速得到目标记录所在的位置。
普通索引
唯一索引:该列上的值不能重复,允许有空值。
主键索引:不允许有空值。
创建主键约束时,mysql 默认会自动创建一个索引
若要实现主键的值不重复,在每次插入新记录时都需要检索数据,所以为了提高检索速度,同时对主键创建索引。
创建唯一约束时,mysql 默认会自动创建一个唯一索引
跟上面的道理一样,通过唯一索引实现唯一约束
边栏推荐
- PCR validation of basic biological experiments in [life sciences]
- [thoughts in the essay] mourn for development technology expert Mao Xingyun
- redis.conf总配置详解
- Word splitting problem
- OneNote User Guide (1)
- SANs证书生成
- Mean Value Coordinates
- Surpass the strongest variant of RESNET! Google proposes a new convolution + attention network: coatnet, with an accuracy of 89.77%!
- Laravel 权限导出
- Ffmpeg principle
猜你喜欢

A real-time target detection model Yolo

Superficial understanding of conditional random fields
![[thoughts in the essay] mourn for development technology expert Mao Xingyun](/img/6b/d1ef40855fc5ba8275dc624ed61dc2.jpg)
[thoughts in the essay] mourn for development technology expert Mao Xingyun

Professional database management software: Valentina Studio Pro for Mac

Open source video recolor code
![Leetcode 450. Delete node in binary search tree [binary search tree]](/img/39/d5c4d424a160635791c4645d6f2e10.png)
Leetcode 450. Delete node in binary search tree [binary search tree]

js 解构赋值
![[reading point paper] yolo9000:better, faster, stronger, (yolov2), integrating various methods to improve the idea of map and wordtree data fusion](/img/b7/0171a637d00e979fb92b82d0c038be.jpg)
[reading point paper] yolo9000:better, faster, stronger, (yolov2), integrating various methods to improve the idea of map and wordtree data fusion

Logiciel professionnel de gestion de base de données: Valentina Studio Pro pour Mac
![[reading papers] dcgan, the combination of generating countermeasure network and deep convolution](/img/31/8c225627177169f1a3d6c48fd7e97e.jpg)
[reading papers] dcgan, the combination of generating countermeasure network and deep convolution
随机推荐
重定向设置参数-RedirectAttributes
[reading paper] generate confrontation network Gan
Opencvshare4 and vs2019 configuration
Matlab: find the inner angle of n-sided concave polygon
05 tabbar navigation bar function
Graduation project - campus old thing recycling system based on stm32
哈夫曼树及其应用
[data analysis and visualization] key points of data drawing 3- spaghetti map
Special topic I of mathematical physics of the sprint strong foundation program
数仓笔记|针对客户维度建模需要关注的5个因素
[data analysis and visualization] key points of data drawing 10- construction of legend
Android lightweight cache processing
vant实现移动端的适配
How to destroy a fragment- How to destroy Fragment?
Retrofit easy to use
Laravel permission export
A real-time target detection model Yolo
Leetcode 926. Flip string to monotonically increasing [prefix and]
[thoughts in the essay] mourn for development technology expert Mao Xingyun
Huffman tree and its application