当前位置:网站首页>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.主键
边栏推荐
- The third part of the construction of the defense system of offensive and defensive exercises is the establishment of a practical security system
- 日本购物网站的网络乞丐功能
- Openresty load balancing
- 通过Go语言创建CA与签发证书
- URL introduction
- Postgresql随手记(10)动态执行EXECUTING语法解析过程
- Linux基础 —— CentOS7 离线安装 MySQL
- Jerry's records are powered by Vbat with a power supply voltage of 4.2V [chapter]
- Daily three questions 6.30
- Jerry's burning of upper version materials requires [chapter]
猜你喜欢

Redis数据类型和应用场景

Paramètres communs de matplotlib

AirServer最新Win64位个人版投屏软件

Yoga27 multidimensional all-in-one computer with excellent appearance and high-end configuration

What is mosaic?

2022 crane driver (limited to bridge crane) examination questions and simulation examination

Linux基础 —— CentOS7 离线安装 MySQL

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

Wechat personal small store one click opening assistant applet development

2021 RoboCom 世界机器人开发者大赛-高职组初赛
随机推荐
What is mosaic?
mysql ---- Oracle中的rownum转换成MySQL
Linux foundation - centos7 offline installation of MySQL
Glass mosaic
CKS CKA CKAD 将终端更改为远程桌面
马赛克后挡板是什么?
Three development trends of enterprise application from the perspective of the third technological revolution
[applet] realize the left and right [sliding] list through the scroll view component
Distance measurement - Hamming distance
“35岁,公司老总,月薪2万送外卖“:时代抛弃你,连声再见都没有
通过Go语言创建CA与签发证书
SWT / anr problem - SWT causes low memory killer (LMK)
实在RPA:银行数字化,业务流程自动化“一小步”,贷款审核效率“一大步”
Jielizhi Bluetooth headset quality control and production skills [chapter]
Development trend and future direction of neural network Internet of things
Matplotlib常用图表
Zhongang Mining: it has inherent advantages to develop the characteristic chemical industry dominated by fluorine chemical industry
SWT/ANR问题--SWT 导致 kernel fuse deadlock
Aaai22 | structural tagging and interaction modeling: a "slim" network for graph classification
flutter Unable to load asset: assets/images/888.png