当前位置:网站首页>sql 优化
sql 优化
2022-07-01 23:04:00 【叮当的猫猫】
limit 优化
一次SQL查询优化原理分析(900W+数据,从17s到300ms)
有一张财务流水表,未分库分表,目前的数据量为9555695,分页查询使用到了limit,优化之前的查询耗时16 s 938 ms (execution: 16 s 831 ms, fetching: 107 ms),按照下文的方式调整SQL后,耗时347 ms (execution: 163 ms, fetching: 184 ms);
操作: 查询条件放到子查询中,子查询只查主键ID,然后使用子查询中确定的主键关联查询其他的属性字段;
原理: 减少回表操作,利用延迟关联或者子查询优化超多分页场景。
-- 优化前SQL
SELECT 各种字段
FROM `table_name`
WHERE 各种条件
LIMIT 0,10;
-- 优化后SQL
SELECT 各种字段
FROM `table_name` main_tale
RIGHT JOIN
(
SELECT 子查询只查主键
FROM `table_name`
WHERE 各种条件
LIMIT 0,10;
) temp_table ON temp_table.主键 = main_table.主键
边栏推荐
- 什么是马赛克?
- 2021 RoboCom 世界机器人开发者大赛-本科组初赛
- Create Ca and issue certificate through go language
- 建模和影视后期有什么关联?
- Three development trends of enterprise application from the perspective of the third technological revolution
- Switch to software testing, knowing these four points is enough!
- 证券开户选哪个证券公司比较好,哪个更安全
- 从第三次技术革命看企业应用三大开发趋势
- 关于游戏性能优化的一些感想
- Openresty load balancing
猜你喜欢

What is the mosaic tailgate?
![Jielizhi, production line assembly link [chapter]](/img/5f/9ea7fd3b93df1fd3ecbfc1b669c831.png)
Jielizhi, production line assembly link [chapter]

What category does the Internet of things application technology major belong to

2021 RoboCom 世界机器人开发者大赛-高职组复赛

Istio、eBPF 和 RSocket Broker:深入研究服务网格

MySQL binlog cleanup

建模和影视后期有什么关联?

Why is PHP called hypertext preprocessor

Redis数据类型和应用场景

CKS CKA CKAD 将终端更改为远程桌面
随机推荐
软件架构的本质
How to display real-time 2D map after rviz is opened
为什么PHP叫超文本预处理器
Typescript enumeration
通过Go语言创建CA与签发证书
CKS CKA ckad change terminal to remote desktop
每日三题 6.29
Programming English vocabulary notebook
Yoga27 multidimensional all-in-one computer with excellent appearance and high-end configuration
Leetcode (34) -- find the first and last positions of elements in a sorted array
Aaai22 | structural tagging and interaction modeling: a "slim" network for graph classification
2021 RoboCom 世界机器人开发者大赛-本科组初赛
MySQL -- convert rownum in Oracle to MySQL
"35 years old, the boss of the company, with a monthly salary of 20000, give away takeout": the times abandoned you, not even saying goodbye
Current situation and future development trend of Internet of things
物联网应用技术专业是属于什么类
Experience of practical learning of Silicon Valley products
Some thoughts on game performance optimization
What is mosaic?
微信个人小商店一键开通助手小程序开发