当前位置:网站首页>根据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语句" 结合前面所提到的两个指标是否有了优化,如果没有任何优化效果,可能就是索引失效了。
总结;创建索引虽然可以大大提高查询的速度,但是会降低更新和插入的速度,因为索引也需要进行更新,所以添加索引尽量结合实际业务需求添加
边栏推荐
- Reading makes people quiet
- 拾光者,云南白药!
- Arduino esp8266 web LED control
- 云成本优化有哪些优秀实践?
- Packet capturing and sorting out external Fiddler -- understanding the toolbar [1]
- __getitem__和__setitem__
- Embedded DSP audio development
- Packet capturing and sorting out external Fiddler -- understanding the toolbar [1]
- Is it reliable to invest in the inter-bank certificate of deposit fund? Is the inter-bank certificate of deposit fund safe
- Writing based on stm32
猜你喜欢

访问网站提示:您未被授权查看该页恢复办法

剑指 Offer 53 - I. 在排序数组中查找数字 I(改进二分)

How to judge that the thread pool has completed all tasks?

Usage details of staticlayout

In the digital era, enterprises must do well in user information security

You got 8K in the 3-year function test, but were overtaken by the new tester. In fact, you are pretending to work hard

Simple elk configuration to realize production level log collection and query practice

R language penalty logistic regression, linear discriminant analysis LDA, generalized additive model GAM, multiple adaptive regression splines Mars, KNN, quadratic discriminant analysis QDA, decision

2022危险化学品经营单位安全管理人员特种作业证考试题库模拟考试平台操作

Flow based depth generation model
随机推荐
为什么大厂压力大,竞争大,还有这么多人热衷于大厂呢?
s32ds跳转到DefaultISR
如何获取GC(垃圾回收器)的STW(暂停)时间?
CI & CD 不可不知!
The horizontal scrolling recycleview displays five and a half in one screen, which is lower than the five average distributions
Apache——阿帕奇简介
建立自己的网站(17)
Embedded DSP audio development
ARM Development Studio build编译报错
基于流的深度生成模型
元宇宙标准论坛成立
[games] Parkour
【Kotlin】在Android官方文档中对其语法的基本介绍和理解
What is the best and safest software to download when buying stocks?
2022年R1快开门式压力容器操作特种作业证考试题库及答案
栈的基本操作(C语言实现)
【iptables&icmp】iptables默认策略中关于icmp协议的说明
RichView TRVStyle TextStyles
JDBC and MySQL databases
Le routage des microservices de la passerelle a échoué au chargement des ressources statiques des microservices