当前位置:网站首页>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.主键
边栏推荐
- Postgresql随手记(10)动态执行EXECUTING语法解析过程
- STM32F030F4驱动TIM1637数码管芯片
- mt管理器测试滑雪大冒险
- Leetcode (34) -- find the first and last positions of elements in a sorted array
- Redis~02 cache: how to ensure data consistency in MySQL and redis when updating data?
- What is the mosaic tailgate?
- The difference between timer and scheduledthreadpoolexecutor
- 每日三题 6.30(2)
- SWT / anr problem - SWT causes low memory killer (LMK)
- Matplotlib常用設置
猜你喜欢
![[micro service sentinel] sentinel integrates openfeign](/img/8b/46156255fd980eb422c7e05d5af7ee.png)
[micro service sentinel] sentinel integrates openfeign

Win 10 mstsc connect RemoteApp

什么是马赛克?

Zero foundation tutorial of Internet of things development

CKS CKA CKAD 将终端更改为远程桌面
![Jielizhi, production line assembly link [chapter]](/img/5f/9ea7fd3b93df1fd3ecbfc1b669c831.png)
Jielizhi, production line assembly link [chapter]

What professional classification does the application of Internet of things technology belong to

MT manager test skiing Adventure

mysql binlog的清理
![Jielizhi Bluetooth headset quality control and production skills [chapter]](/img/3e/571d246d211a979e948dae1de56e93.png)
Jielizhi Bluetooth headset quality control and production skills [chapter]
随机推荐
Experience of practical learning of Silicon Valley products
Matplotlib常用設置
Current situation and future development trend of Internet of things
硅谷产品实战学习感触
物联网应用技术专业是属于什么类
Practical application and extension of plain framework
CKS CKA CKAD 将终端更改为远程桌面
力扣今日题-241. 为运算表达式设计优先级
玻璃马赛克
物联网技术应用属于什么专业分类
Create Ca and issue certificate through go language
【无标题】
建模和影视后期有什么关联?
2022安全员-C证考试题模拟考试题库及模拟考试
想请教股票开户要认识谁?在线开户是安全么?
SWT/ANR问题--SWT 导致 low memory killer(LMK)
每日三题 6.30(2)
"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
Know --matplotlib
Practical application and extension of plain framework