当前位置:网站首页>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.主键
边栏推荐
- 2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板
- 共享电商的背后: 共创、共生、共享、共富,共赢的共富精神
- [micro service sentinel] @sentinelresource details
- Yunxin small class | common cognitive misunderstandings in IM and audio and video
- The digital summit is popular, and city chain technology has triggered a new round of business transformation
- JS - use of arguments
- Matplotlib common charts
- What professional classification does the application of Internet of things technology belong to
- y53.第三章 Kubernetes从入门到精通 -- ingress(二六)
- AirServer最新Win64位个人版投屏软件
猜你喜欢

云信小课堂 | IM及音视频中常见的认知误区

Commemorate becoming the first dayus200 tripartite demo contributor

Development trend and future direction of neural network Internet of things

What is mosaic?

硅谷产品实战学习感触

【微服务|Sentinel】sentinel整合openfeign

2021 RoboCom 世界机器人开发者大赛-本科组初赛

RPA: Bank digitalization, business process automation "a small step", and loan review efficiency "a big step"

Zhongang Mining: it has inherent advantages to develop the characteristic chemical industry dominated by fluorine chemical industry

from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
随机推荐
物联网应用技术专业是属于什么类
Jielizhi, production line assembly link [chapter]
Istio、eBPF 和 RSocket Broker:深入研究服务网格
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
实在RPA:银行数字化,业务流程自动化“一小步”,贷款审核效率“一大步”
神经网络物联网的未来趋势与发展
问题随记 —— /usr/bin/perl is needed by MySQL-server-5.1.73-1.glibc23.x86_64
[LeetCode] 最后一个单词的长度【58】
【微服务|Sentinel】SentinelResourceAspect详解
Redis~02 缓存:更新数据时如何保证MySQL和Redis中的数据一致性?
Switch to software testing, knowing these four points is enough!
MySQL binlog cleanup
每日三题 6.30(2)
Distance measurement - Hamming distance
从第三次技术革命看企业应用三大开发趋势
Aaai22 | structural tagging and interaction modeling: a "slim" network for graph classification
Zhongang Mining: it has inherent advantages to develop the characteristic chemical industry dominated by fluorine chemical industry
物联网开发零基础教程
Why is PHP called hypertext preprocessor
Behind sharing e-commerce: the spirit of CO creation, symbiosis, sharing, CO prosperity and win-win