当前位置:网站首页>MySQL索引优化之分页探索详细介绍
MySQL索引优化之分页探索详细介绍
2022-04-23 11:02:00 【liming89】
文章来源: 学习通http://www.bdgxy.com/
??MySQL??索引优化之分页探索
表结构
CREATE TABLE `demo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '姓名',
`age` int(11) NOT NULL DEFAULT '0' COMMENT '年龄',
`position` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '职位',
`card_num` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '工卡号',
PRIMARY KEY (`id`),
KEY `index_union` (`name`,`age`,`position`)
) ENGINE=InnoDB AUTO_INCREMENT=450003 DEFAULT CHARSET=utf8;
450003条数据
limit分页执行情况

像select * from demo limit 90000,10;考虑到回表,所以mysql干脆选择全表扫描。
mysql不是直接从第90000行开始计算10条,而是从第一个叶子节点开始计数,计算90010行。
案例一

针对上图,当id是连续自增的时候,可以用主键筛选出id=90000之后的数据。因为主键的索引是B+树结构,本身就是有序的。

案例二

先按照name排序,然后再从第90000行起找10行,虽然name是索引,但select的列在index_union索引树上并没有保存。
所以还会涉及到回表,于是mysql直接选择扫主键索引树的叶子结点,先将40多万数据根据name排好序,然后计算90000行+10行。
优化方法:利用子查询解决最消耗时间的排序和回表问题,联合索引树种保存有主键id,order by name的话可以将name、age、position整个索引充分使用因为确定了最左列的排序,其余的俩列age、和position其实也是
排好序的了,通过Extra字段也可以是使用了索引树做排序。
最外层的查询是根据主键来关联的,所以几乎可以忽略。10+10 因为id是主键,可以直接拿临时表10条数据去扫。

到此这篇关于MySQL索引优化之分页探索详细介绍的文章就介绍到这了,更多相关MySQL分页探索内容请搜索菜鸟教程www.piaodoo.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持菜鸟教程www.piaodoo.com!
版权声明
本文为[liming89]所创,转载请带上原文链接,感谢
https://blog.csdn.net/liming89/article/details/124333687
边栏推荐
- Notes on concurrent programming of vegetables (IX) asynchronous IO to realize concurrent crawler acceleration
- 学习 Go 语言 0x07:《Go 语言之旅》中 Stringer 练习题代码
- SQL Server recursive query of superior and subordinate
- FileProvider 路径配置策略的理解
- The courses bought at a high price are open! PHPer data sharing
- 妊娠箱和分娩箱的区别
- Cygwin 中的 rename 用法
- 闹钟场景识别
- 26. 删除有序数组中的重复项
- Learning Notes 6 - Summary of several deep learning convolutional neural networks
猜你喜欢

Google Earth engine (GEE) - scale up the original image (taking Hainan as an example)

About the three commonly used auxiliary classes of JUC

STM32接电机驱动,杜邦线供电,然后反烧问题

C语言之结构体(进阶篇)

Visual Road (XII) detailed explanation of collection class

Visual common drawing (I) stacking diagram

Notes on concurrent programming of vegetables (V) thread safety and lock solution

Introduction to neo4j authoritative guide, recommended by Qiu Bojun, Zhou Hongxiang, Hu Xiaofeng, Zhou Tao and other celebrities

The courses bought at a high price are open! PHPer data sharing

Excel·VBA数组冒泡排序函数
随机推荐
Mba-day5 Mathematics - application problems - engineering problems
Simple thoughts on the design of a microblog database
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
Ueditor -- limitation of 4m size of image upload component
Visual Road (XII) detailed explanation of collection class
Google Earth engine (GEE) - scale up the original image (taking Hainan as an example)
学习 Go 语言 0x02:对切片 Slice 的理解
A diary of dishes | 238 Product of arrays other than itself
web三大组件(Servlet,Filter,Listener)
Visual solutions to common problems (VIII) mathematical formulas
Visual common drawing (IV) histogram
Hikvision face to face summary
Problems of class in C # and database connection
Introduction to neo4j authoritative guide, recommended by Qiu Bojun, Zhou Hongxiang, Hu Xiaofeng, Zhou Tao and other celebrities
RESTful和SOAP的区别
Typora operation skill description (I) md
活动进行时! 点击链接加入直播间参与“AI真的能节能吗?”的讨论吧!
Installing MySQL with CentOS / Linux
MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了
26. 删除有序数组中的重复项