当前位置:网站首页>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.主键
边栏推荐
- 问题随记 —— /usr/bin/perl is needed by MySQL-server-5.1.73-1.glibc23.x86_64
- Matplotlib common charts
- 内存泄露和内存溢出的区别是什么?
- 通过Go语言创建CA与签发证书
- 物联网技术应用属于什么专业分类
- SWT/ANR问题--SWT 导致 kernel fuse deadlock
- Redis~02 缓存:更新数据时如何保证MySQL和Redis中的数据一致性?
- [micro service sentinel] @sentinelresource details
- Matplotlib common settings
- RPA: Bank digitalization, business process automation "a small step", and loan review efficiency "a big step"
猜你喜欢
Istio, ebpf and rsocket Broker: in depth study of service grid
日本购物网站的网络乞丐功能
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
距离度量 —— 汉明距离(Hamming Distance)
AirServer最新Win64位个人版投屏软件
What category does the Internet of things application technology major belong to
RPA: Bank digitalization, business process automation "a small step", and loan review efficiency "a big step"
mt管理器测试滑雪大冒险
ARP报文头部格式和请求流程
Jerry's records are powered by Vbat with a power supply voltage of 4.2V [chapter]
随机推荐
每日三题 6.30(2)
What is the relationship between modeling and later film and television?
Matplotlib常用设置
Microservice stability management
Matplotlib常用設置
[micro service sentinel] sentinel integrates openfeign
SWT / anr problem - SWT causes low memory killer (LMK)
Jielizhi, production line assembly link [chapter]
Stm32f030f4 drives tim1637 nixie tube chip
MT manager test skiing Adventure
Why is PHP called hypertext preprocessor
2021 RoboCom 世界机器人开发者大赛-高职组复赛
Understanding threads
Behind sharing e-commerce: the spirit of CO creation, symbiosis, sharing, CO prosperity and win-win
Redis数据类型和应用场景
Notes on problems - /usr/bin/perl is needed by mysql-server-5.1.73-1 glibc23.x86_ sixty-four
Commemorate becoming the first dayus200 tripartite demo contributor
Who do you want to know when opening a stock account? Is it safe to open an account online?
What is the mosaic tailgate?
实在RPA:银行数字化,业务流程自动化“一小步”,贷款审核效率“一大步”