当前位置:网站首页>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.主键
边栏推荐
- Leetcode(34)——在排序数组中查找元素的第一个和最后一个位置
- Zhongang Mining: it has inherent advantages to develop the characteristic chemical industry dominated by fluorine chemical industry
- ShanDong Multi-University Training #3
- 2021 RoboCom 世界机器人开发者大赛-本科组初赛
- De PIP. Interne. CLI. Main Import main modulenotfounderror: No module named 'PIP'
- The digital summit is popular, and city chain technology has triggered a new round of business transformation
- Jielizhi, production line assembly link [chapter]
- 建模和影视后期有什么关联?
- [micro service sentinel] sentinel integrates openfeign
- 2022 safety officer-c certificate examination question simulation examination question bank and simulation examination
猜你喜欢

Postgresql源码(57)HOT更新为什么性能差距那么大?

2022年R1快开门式压力容器操作考题及答案

Huisheng Huiying 2022 intelligent, fast and simple video editing software

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

Paramètres communs de matplotlib

神经网络物联网的发展趋势和未来方向

flutter Unable to load asset: assets/images/888. png

物联网技术应用属于什么专业分类

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

win 10 mstsc连接 RemoteApp
随机推荐
Wechat personal small store one click opening assistant applet development
Practical application and extension of plain framework
Redis~02 缓存:更新数据时如何保证MySQL和Redis中的数据一致性?
2022安全员-C证考试题模拟考试题库及模拟考试
力扣今日题-241. 为运算表达式设计优先级
神经网络物联网的未来趋势与发展
What is the mosaic tailgate?
De PIP. Interne. CLI. Main Import main modulenotfounderror: No module named 'PIP'
js——arguments的使用
STM32F030F4驱动TIM1637数码管芯片
2021 RoboCom 世界机器人开发者大赛-高职组复赛
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
Istio, ebpf and rsocket Broker: in depth study of service grid
Is it safe to choose mobile phone for stock trading account opening in Shanghai?
Some thoughts on game performance optimization
Yunxin small class | common cognitive misunderstandings in IM and audio and video
JS - use of arguments
Notes on problems - /usr/bin/perl is needed by mysql-server-5.1.73-1 glibc23.x86_ sixty-four
通过Go语言创建CA与签发证书
[micro service sentinel] @sentinelresource details