cfanbo / cfanbo.github.io

1 stars 0 forks source link

一张图让你彻底理解聚簇索引与普通索引的区别[经典] | 学习笔记 #198

Open cfanbo opened 1 year ago

cfanbo commented 1 year ago

https://blog.haohtml.com/archives/17116/

下面分析下索引和锁的关系。 1)delete from msg where id=2; 由于id是主键,因此直接锁住整行记录即可。 图5 2)delete from msg where token=’ cvs’; 由于token是二级索引,因此首先锁住二级索引(两行),接着会锁住相应主键所对应的记录; 图6 3)delete from msg where message=订单号是多少’; message没有索引,所以走的是全表扫描过滤。这时表上的各个记录都将添加上X锁。 图7 强烈推荐阅读: https://yq.aliyun.com/articles/5533