当前位置:网站首页>我秃了!唯一索引、普通索引我该选谁?
我秃了!唯一索引、普通索引我该选谁?
2022-07-28 12:18:00 【InfoQ】

1、在SELECT中,唯一索引和普通索引的区别
select id from T where id_card = 666;
- 将磁盘块1从磁盘加载到内存,发生一次IO ,在内存中使用二分查找方式找到 666 在600和700 之间,锁定磁盘块1的P2 指针。
- 通过磁盘块1 的 P2 指针地址把磁盘块3 加载到内存,发生第二次IO ,锁定磁盘块3 的 P2 指针
- 通过磁盘块3 的P2指针加载磁盘块7到内存,发生第三次 IO,同时根据二分查找找到666 查询结束。
- 普通索引:查到第一条id_card=666 后,然后继续往后查找直到碰到第一个 id_card<>666 的记录时,结束。
- 唯一索引:由于索引定义了唯一性,查找到第一个满足条件的记录后,直接结束。

2、在DML中,唯一索引和普通索引的区别

- 有SQL线程访问这个数据页;
- master thread线程每秒或每10秒进行一次merge change buffer的操作;
- 在数据库正常关闭的时候。
- 对于普通索引(非唯一索引)的DML操作来说,当待更新的数据页在内存中时,找到前值和后值的区间插入即可;当待更新的数据页在不在内存中时,直接把操作写到Change buffer就完事儿了。舒服!
- 而对于唯一索引,当待更新的数据页在不在内存中时,索引每次都得把数据页读到内存中判断唯一性,将数据从磁盘读入内存涉及大量随机IO的访问,慢的一批,当遇到高频写操作时??唉,别想了,难受!

边栏推荐
- 2021-10-06
- [FPGA]: ISE generates MCS file and burning process
- Cesium pit -- pit used by various API calls and API itself
- Shell basic concepts and variables
- kotlin学习笔记3——Lambda编程
- Gamestop bear market entered NFT trading, and established game retailers took advantage of Web3 to make a second spring
- 少儿编程 电子学会图形化编程等级考试Scratch二级真题解析(判断题)2022年6月
- Rust 从入门到精通01-简介
- Original juice multifunctional Juicer touch chip-dlt8t02s-jericho
- LeetCode·每日一题·1331.数组序号转换·离散化
猜你喜欢

Parent and child of treeselect

基于神经网络的帧内预测和变换核选择

leetcode-136.只出现一次的数字

Gamestop bear market entered NFT trading, and established game retailers took advantage of Web3 to make a second spring

Definition of option basis

Shell basic concepts and variables

Map tiles: detailed explanation of vector tiles and grid tiles

Call / put option price curve

gicv3 spi register

Realize the mutual value transfer between main window and sub window in WPF
随机推荐
butterfly spreads
今日睡眠质量记录75分
Black cat takes you to learn EMMC protocol chapter 27: what is EMMC's dynamic capacity?
Vditor 渲染器如何做到服务端渲染(SSR)?
【黑马早报】字节估值缩水,降至2700亿美元;“二舅”视频作者回应抄袭;任泽平称取消商品房预售制是大势所趋;美联储宣布再加息75个基点...
.NET桌面开发的一些思考
Gamestop bear market entered NFT trading, and established game retailers took advantage of Web3 to make a second spring
8、 Kubernetes network and load balancing
nport串口服务器配置网址(串口服务器是不是网口转串口)
Databinding+livedata can easily realize skin changing without restart
The form select in antd is received before it is selected
功率放大器和匹配网络学习
With 433 remote control UV lamp touch chip-dlt8sa20a-jericho
Why neural networks are ineffective?
[embedded C foundation] Part 3: constants and variables
JS method of splitting strings
微念“失去”李子柒的这一年
基于pytorch卷积人脸表情识别–毕业设计「建议收藏」
Tidb 6.x in action was released, a summary of 6.x practices that condense the collective wisdom of the community!
剖析 kubernetes 集群内部 DNS 解析原理