当前位置:网站首页>View the SQL execution plan according to explain and optimize the SQL
View the SQL execution plan according to explain and optimize the SQL
2022-06-28 03:22:00 【Programming Xiaobai who loves Java】
1. Use Explain Keyword view SQL Implementation plan of
Statement for :EXPLAIN " Yours sql sentence "

And then according to the above figure sql The implementation plan focuses on two main points 1.Type Whether to query all tables ALL Represents full table query ,2. Focus on rows See how many lines were scanned ( Estimate ), Both can determine whether optimization is needed
2. Determine the sql It needs to be optimized
Use show index from tableName( Table name )
See which indexes the table uses , To avoid index creation conflicts
3. Combine the previous two operations to determine which field to use the index on , The suggestion is in where Add an index to the field after the condition , But there is one thing that needs special attention : It doesn't make sense to add an index to the status field or gender field ( Try to select the field with high discrimination as the index , The formula of discrimination is count(distinct col)/count(*), Express The proportion of fields that do not repeat , The larger the ratio, the fewer records we scan , The only key differentiator is 1, And some states 、 Gender fields may be differentiated in front of big data 0. Add an index to the gender field , Does not significantly speed up Retrieval Speed
Link to the original text :https://blog.csdn.net/qq_43193797/article/details/88592605)
The statement to create the index is :create index Custom index name on Table name ( Field name )
4. Create the index and execute it again explain "sql sentence " Whether the two indicators mentioned above have been optimized , If there is no optimization effect , Maybe the index is invalid .
summary ; Although creating an index can greatly improve the speed of query , But it will reduce the speed of updating and inserting , Because the index also needs to be updated , Therefore, the index should be added according to the actual business needs
边栏推荐
- Simple elk configuration to realize production level log collection and query practice
- 嵌入式软件开发中必备软件工具
- [today in history] June 23: Turing's birthday; The birth of the founder of the Internet; Reddit goes online
- Heartless sword Chinese English bilingual poem 004 Sword
- Is your IOT security strong enough?
- Simple file transfer protocol TFTP
- RichView TRVStyle ParaStyles
- RichView TRVStyle
- RichView TRVStyle TextStyles
- 剑指 Offer 53 - I. 在排序数组中查找数字 I(改进二分)
猜你喜欢

Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队

微信小程序中生成二维码

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

如何编写简洁代码?(上)

A16z: metauniverse unlocks new opportunities in game infrastructure

腾讯游戏发布40多款产品与项目 其中12款为新游戏

Opencv -- geometric space transformation (affine transformation and projection transformation)

Simple file transfer protocol TFTP
![[iptables & ICMP] description of ICMP Protocol in iptables default policy](/img/9d/85027ea0b0bc9c6494ba41daed9f38.png)
[iptables & ICMP] description of ICMP Protocol in iptables default policy

idea自动生成代码
随机推荐
R language penalty logistic regression, linear discriminant analysis LDA, generalized additive model GAM, multiple adaptive regression splines Mars, KNN, quadratic discriminant analysis QDA, decision
[issue 21] face to face experience of golang engineer recruited by Zhihu Society
剑指 Offer 49. 丑数(三指针法)
数字化时代,企业须做好用户信息安全
Tardigrade:Trino 解决 ETL 场景的方案
R1 Quick Open Pressure Vessel Operation Special Operation Certificate Examination Library and Answers in 2022
Heartless sword English Chinese bilingual poem 004 Meditation
How fiddle uses agents
Built in functions for MySQL database operations
service实现类里面为何一直报红
Apache - Introduction à Apache
【Kotlin】在Android官方文档中对其语法的基本介绍和理解
[games] Parkour
PPT制作小技巧
在excel文件上设置下拉选项
2022危险化学品经营单位安全管理人员特种作业证考试题库模拟考试平台操作
Is it safe to buy stocks and open an account through the account opening link of the broker manager? Want to open an account for stock trading
Dataloader参数collate_fn的使用
2022 electrician (elementary) recurrent training question bank and online simulation examination
apache、iis6、ii7独立ip主机屏蔽限制ip访问