当前位置:网站首页>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源码(58)元组拼接heap_form_tuple剖析
- Zero foundation tutorial of Internet of things development
- Leetcode (34) -- find the first and last positions of elements in a sorted array
- Airserver latest win64 bit personal screen projection software
- 问题随记 —— file /usr/share/mysql/charsets/README from install of MySQL-server-5.1.73-1.glibc23.x86_64 c
- Is it safe to choose mobile phone for stock trading account opening in Shanghai?
- Create Ca and issue certificate through go language
- [understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing
- 2022年危险化学品经营单位安全管理人员考试题及在线模拟考试
- Jielizhi, production line assembly link [chapter]
猜你喜欢

Redis~02 cache: how to ensure data consistency in MySQL and redis when updating data?

Linux foundation - centos7 offline installation of MySQL

日本购物网站的网络乞丐功能

CADD课程学习(3)-- 靶点药物相互作用

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

SWT/ANR问题--SWT 导致 kernel fuse deadlock

Matplotlib常用设置

物联网现状及未来发展趋势

问题随记 —— file /usr/share/mysql/charsets/README from install of MySQL-server-5.1.73-1.glibc23.x86_64 c

Zhongang Mining: it has inherent advantages to develop the characteristic chemical industry dominated by fluorine chemical industry
随机推荐
2022 R1 fast opening pressure vessel operation test questions and answers
Switch to software testing, knowing these four points is enough!
有没有一段代码,让你为人类的智慧所折服
Timer和ScheduledThreadPoolExecutor的区别
Experience of practical learning of Silicon Valley products
CADD course learning (3) -- target drug interaction
2022年危险化学品经营单位安全管理人员考试题及在线模拟考试
Istio, ebpf and rsocket Broker: in depth study of service grid
想请教股票开户要认识谁?在线开户是安全么?
转行软件测试,知道这四点就够了!
Postgresql源码(58)元组拼接heap_form_tuple剖析
2021 RoboCom 世界机器人开发者大赛-高职组复赛
Postgresql随手记(10)动态执行EXECUTING语法解析过程
Create Ca and issue certificate through go language
MySQL binlog cleanup
Daily three questions 6.28
Zhao Fuquan: to ensure supply in the short term, we should build a safe, efficient and resilient supply chain in the long term
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
Which securities company is better and which is safer to open a securities account
每日三题 6.30(2)