当前位置:网站首页>根据Explain查看sql执行计划,对SQL进行优化
根据Explain查看sql执行计划,对SQL进行优化
2022-06-28 02:16:00 【热爱Java的编程小白】
1.使用Explain关键字查看SQL的执行计划
语句为:EXPLAIN "你的sql语句"
而后根据上图查出来的sql执行计划主要关注两点1.Type是否全表查询 ALL代表全表查询,2.关注rows 查看扫描了多少行(估算值),两者既可判定是否需要优化
2.确定该sql是需要优化的
使用 show index from tableName(表名)
查看该表使用了哪些索引,以免索引创建冲突
3.结合前两次操作判断在哪个字段上面使用索引,建议是在where条件后面的字段添加索引,但是有一点需要特别注意:状态字段或者性别字段添加索引是无意义的(尽量选择区分度高的字段作为索引,区分度的公式是 count(distinct col)/count(*),表示 字段不重复的比例,比例越大我们扫描的记录数越少,唯一键的区分度是 1,而一些状态、 性别字段可能在大数据面前区分度就是 0。在性别字段上增加索引,并不能明显加快检索 速度
原文链接:https://blog.csdn.net/qq_43193797/article/details/88592605)
创建索引的语句是:create index 自定义索引名 on 表名(字段名)
4.创建索引后再去执行一遍explain "sql语句" 结合前面所提到的两个指标是否有了优化,如果没有任何优化效果,可能就是索引失效了。
总结;创建索引虽然可以大大提高查询的速度,但是会降低更新和插入的速度,因为索引也需要进行更新,所以添加索引尽量结合实际业务需求添加
边栏推荐
- Mixed programming of C language and assembly language in stm32
- 拾光者,云南白药!
- 【iptables&icmp】iptables默认策略中关于icmp协议的说明
- You got 8K in the 3-year function test, but were overtaken by the new tester. In fact, you are pretending to work hard
- [plug in -statistical] statistics the number of code lines and related data
- 【活动早知道】LiveVideoStack近期活动一览
- ETCD数据库源码分析——集群间网络层服务端RaftHandler
- Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
- nn.Parameter和torch.nn.init系列函数给模型参数初始化
- 新手开哪家的证券账户是比较好?炒股开户安全吗
猜你喜欢
CI & CD 不可不知!
2021年软件测试工具总结——模糊测试工具
s32ds跳转到DefaultISR
音视频技术开发周刊 | 251
分布式事务—基于消息补偿的最终一致性方案(本地消息表、消息队列)
Opencv -- geometric space transformation (affine transformation and projection transformation)
2022年R1快开门式压力容器操作特种作业证考试题库及答案
Why are so many people keen on big factories because of the great pressure and competition?
项目实战!手把手教你 Jmeter 性能测试
Raspberry pie - environment settings and cross compilation
随机推荐
Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
论文阅读:Generative Adversarial Transformers
2022年R1快开门式压力容器操作特种作业证考试题库及答案
Le routage des microservices de la passerelle a échoué au chargement des ressources statiques des microservices
windows 2003 64位系统php运行报错:1% 不是有效的 win32 应用程序
Summary of software testing tools in 2021 - fuzzy testing tools
In the digital era, enterprises must do well in user information security
The first in the industry! MOS sub evaluation model for subjective video quality experience that can run on mobile devices!
Tardigrade:Trino 解决 ETL 场景的方案
collections.defaultdict()的使用
简单ELK配置实现生产级别的日志采集和查询实践
[iptables & ICMP] description of ICMP Protocol in iptables default policy
空闲中断无法清除
Single page application (SPA) hash route and historical API route
Embedded DSP audio development
R语言惩罚逻辑回归、线性判别分析LDA、广义加性模型GAM、多元自适应回归样条MARS、KNN、二次判别分析QDA、决策树、随机森林、支持向量机SVM分类优质劣质葡萄酒十折交叉验证和ROC可视化
Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
RichView TRVStyle TextStyles
Gateway microservice routing failed to load microservice static resources
[today in history] June 23: Turing's birthday; The birth of the founder of the Internet; Reddit goes online