当前位置:网站首页>SQL优化问题的简述
SQL优化问题的简述
2022-07-06 10:13:00 【面向鸿蒙编程】
SQL优化的7个方面
- 创建索引
- 避免索引失效
- 锁粒度(行锁还是表锁)
- 分页查询优化
- 避免查询所有字段
- 分析SQL的执行计划
- show profile 分析SQL的执行性能
创建索引
- 禁止给表中的每一列都建立单独的索引
- 每个Innodb表必须有一个主键
- 要注意组合索引的字段顺序
- 优先考虑覆盖索引
- 避免使用外键约束
避免索引失效(失效场景)
- 以%开头的LIKE查询
- 在索引列上的操作,函数upper()等,or、!=、<>、not in等等
- 创建了组合索引,但是查询条件不满足“最左匹配”原则
- 查询条件中使用or,且or的前后条件中有一个列没有索引,则其中涉及的索引就都不会被使用
锁粒度(行锁 还是 表锁)
- MySQL 的存储引擎分为两大类: MyISAM 和 InnoDB
- MyISAM 支持只表锁
- InnoDB 支持行锁和表锁
- 更新操作时,为了保证表数据的准确性,通常会加锁,为了提高系统的高并发能力,我们通常建议采用行锁,减少锁冲突、锁等待的时间。所以,存储引擎通常会选择 InnoDB
分页查询优化
避免查询所有字段
分析SQL的执行计划
show profile 分析SQL的执行性能
后续会逐渐完善...此章节先打个点
边栏推荐
- Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology
- C language exchanges two numbers through pointers
- Getting started with pytest ----- test case pre post, firmware
- Getting started with pytest ----- allow generate report
- Manifest of SAP ui5 framework json
- 推荐好用的后台管理脚手架,人人开源
- After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
- OliveTin能在网页上安全运行shell命令(上)
- DNS hijacking
- Jerry's access to additional information on the dial [article]
猜你喜欢
Compilation principle - top-down analysis and recursive descent analysis construction (notes)
重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
The easycvr authorization expiration page cannot be logged in. How to solve it?
STM32按键状态机2——状态简化与增加长按功能
Distiller les connaissances du modèle interactif! L'Université de technologie de Chine & meituan propose Virt, qui a à la fois l'efficacité du modèle à deux tours et la performance du modèle interacti
Getting started with pytest ----- test case pre post, firmware
递归的方式
Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
Four processes of program operation
随机推荐
DNS hijacking
30 分钟看懂 PCA 主成分分析
Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
declval(指导函数返回值范例)
The difference between parallelism and concurrency
李书福为何要亲自挂帅造手机?
Dichotomy (integer dichotomy, real dichotomy)
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
OliveTin能在网页上安全运行shell命令(上)
1700C - Helping the Nature
MS-TCT:Inria&SBU提出用于动作检测的多尺度时间Transformer,效果SOTA!已开源!(CVPR2022)...
Rb157-asemi rectifier bridge RB157
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
转载:基于深度学习的工业品组件缺陷检测技术
Jerry is the custom background specified by the currently used dial enable [chapter]
关于这次通信故障,我想多说几句…
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
從交互模型中蒸餾知識!中科大&美團提出VIRT,兼具雙塔模型的效率和交互模型的性能,在文本匹配上實現性能和效率的平衡!...
MSF横向之MSF端口转发+路由表+SOCKS5+proxychains
2022 Summer Project Training (I)