当前位置:网站首页>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
边栏推荐
- Kaggle - real battle of house price prediction
- 【leetcode】102. Sequence traversal of binary tree
- 学习 Go 语言 0x01:从官网开始
- SQL Server recursive query of superior and subordinate
- Resolution and size of mainstream mobile phones
- About the three commonly used auxiliary classes of JUC
- 解决方案架构师的小锦囊 - 架构图的 5 种类型
- 学习 Go 语言 0x06:《Go 语言之旅》中 斐波纳契闭包 练习题代码
- Visual common drawing (IV) histogram
- 学习网站资料
猜你喜欢

MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了

JVM - common parameters

Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area

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

Intuitive understanding entropy

《Neo4j权威指南》简介,求伯君、周鸿袆、胡晓峰、周涛等大咖隆重推荐

UEditor之——图片上传组件大小4M的限制

Mysql8.0安装指南

SVN的使用:

Typora operation skill description (I) md
随机推荐
MBA-day5数学-应用题-工程问题
Mba-day5 Mathematics - application problems - engineering problems
Cygwin 中的 rename 用法
Kaggle - real battle of house price prediction
Special members and magic methods
Is the pointer symbol of C language close to variable type or variable name?
数据库管理软件SQLPro for SQLite for Mac 2022.30
学习 Go 语言 0x04:《Go 语言之旅》中切片的练习题代码
Alarm scene recognition
PlatoFarm推出正式版游戏经济模型的特点分析
Cumcm 2021 - B: préparation d'oléfines C4 par couplage éthanol (2)
How to bind a process to a specified CPU
Facing the global market, platefarm today logs in to four major global platforms such as Huobi
学习 Go 语言 0x03:理解变量之间的依赖以及初始化顺序
VIM + ctags + cscope development environment construction guide
Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)
Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area
HuggingFace
全栈交叉编译X86完成过程经验分享
Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes