当前位置:网站首页>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
边栏推荐
- 测试要掌握的技术有哪些?软件测试必懂的数据库设计大全篇
- What are the technologies to be mastered in the test? Database design for software testing
- 2022电工(初级)复训题库及在线模拟考试
- Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
- [today in history] June 18: JD was born; The online store platform Etsy was established; Facebook releases Libra white paper
- Packet capturing and sorting out external Fiddler -- understanding the toolbar [1]
- 十年职场软件工程师感悟
- Notepad++--列编辑模式--用法/实例
- 多快好省,低门槛AI部署工具FastDeploy测试版来了!
- In the digital era, enterprises must do well in user information security
猜你喜欢

无代码软件发展简史及未来趋势

栈的基本操作(C语言实现)

2022安全员-C证考试题库模拟考试平台操作

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

Flow based depth generation model

音视频技术开发周刊 | 251

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

CI & CD 不可不知!

视频编解码性能优化与实现

CMU puts forward a new NLP paradigm - reconstructing pre training, and achieving 134 high scores in college entrance examination English
随机推荐
RichView TRVStyle TextStyles
华为设备WLAN基本业务配置命令
访问网站提示:您未被授权查看该页恢复办法
基于流的深度生成模型
网上股票投资交流群安全吗?进群免费开户靠谱嘛?
Flask Foundation: template inheritance + static file configuration
Tips for visiting the website: you are not authorized to view the recovery method of this page
s32ds跳转到DefaultISR
A16z: metauniverse unlocks new opportunities in game infrastructure
您的物联网安全性是否足够强大?
Simple file transfer protocol TFTP
根据Explain查看sql执行计划,对SQL进行优化
Arduino esp8266 web LED control
[522. longest special sequence II]
Redis搭建集群【简单】
collections.defaultdict()的使用
CI & CD 不可不知!
【522. 最长特殊序列 II】
Is online stock investment exchange group safe? Is it reliable to open an account for free?
2022危险化学品经营单位安全管理人员特种作业证考试题库模拟考试平台操作