当前位置:网站首页>Common SQL optimization
Common SQL optimization
2022-04-21 21:31:00 【follow_ me!】
Summarize the common sql Optimize , Avoid invalid queries from 、 Use index correctly 、 Avoid index invalidation 、 The other four aspects of optimization are discussed
Rule one : Avoid querying invalid data
Avoid using select * operation , We don't use all the time fields , Reading all fields and transmitting more data over the network will lead to performance degradation .
Rule two : Add the correct index
The most effective tuning is to add indexes , Adding indexes can avoid full table scanning ; And we should avoid the operation of index invalidation after adding an index ;

Should be indexed 4 place :
- Where The fields that often follow
- Order by Keywords after sorting
- Group by Keywords after grouping
- Join on Keywords after
Rule 3 : Try to avoid index invalidation
Actions to avoid , These operations will result in invalidation even if the index is added :
- Like When the operation wildcard appears on the left , Such as like % Wenlong , Because the index sorts the data , Wildcard characters appear on the left, which invalidates the sorting , This causes the index to fail .
How to optimize : Use should be avoided , If there is such a need , have access to INSTR(str, substr) replace , Full text search engines can also be considered when the data is large , Such as ES(Elasticsearch)

- Avoid using in And not in, Can cause indexes to fail ;
How to optimize : If values are continuously available between and Instead of , If not continuous, you can use EXISTS And NOT EXISTS Instead of ; because EXISTS Indexed

- Where The following index fields have expression operations or use functions, which will lead to index invalidation
How to optimize : Expression 、 The function operation moves to the right of the equal sign

- Where In the sentence , If you use is null or is not null To determine the index key , Index failure
How to optimize : Give default

- Or use union Instead of ,or The database engine will abandon the index for full table scanning
- Avoid using where 1=1 , Tagging ,where 1=1 The database engine will abandon the index for full table scanning
Rule four : Other optimization
Can page , Can batch
版权声明
本文为[follow_ me!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212128071873.html
边栏推荐
- 物联网lora无线数传模块应用案例:LoRawan网关通信技术
- Reflex WMS系统,跟SAP系统的几个神似之处
- AES topics involved in CTF crypto
- Crypto中常用的数据类型互转方式
- 32-bit and 64 bit computers
- 聪明的人脸识别3——Pytorch 搭建自己的Facenet人脸识别平台
- JVM 从入门到放弃之 ZGC 垃圾收集器精讲
- Solve the problem that domestic mobile phones cannot register Google Gmail accounts
- Dynamically connecting data sources and transaction rollback
- 读书破万“卷”:国民阅读洞察2022
猜你喜欢

微软 | 通过对比学习预训练的多语言分子表征学习

Cross compile C program for rk3568 development board

Information visualization large screen display board (with download connection)

神经网络学习小记录57——各类激活函数Activation Functions介绍与优缺点分析

32-bit and 64 bit computers

CTF Crypto中涉及的AES题目

Others - understand CGI, fastcgi, WSGI, uwsgi and uwsgi

Communication between parent and child processes (II) -- four cases of anonymous pipeline communication

JVM 从入门到放弃之 ZGC 垃圾收集器精讲

Crypto中常用的数据类型互转方式
随机推荐
Multi tenant points system function list
Anxun cup 2021_ Crypto_ Reappearance
聪明的人脸识别4——Pytorch 利用Retinaface+Facenet搭建人脸识别平台
Bailian3722 因子问题【枚举】
Bailian4004 数字组合【递归+DP】
力扣解法汇总824-山羊拉丁文
841. String hash (string hash template)
Red sun shooting range -- intranet penetration practice
Reading breaks ten thousand "volumes": National Reading insight 2022
【Selenium 自学系列】(一)Selenium第一个例子及交互原理
读书破万“卷”:国民阅读洞察2022
Detailed explanation of kubernetes (V) -- core object of kubernetes
[spark] (task5) fundamentals of sparkml (classification | clustering model)
Eeasybi report system data source selection code development manual
解决国内手机无法注册Google gmail账户问题
Bailian4006 小兔子捡金币【模拟】
Those things about SAP - Career - 36 - from the subject of "fixed assets liquidation"
Bailian3752 走迷宫【BFS】
TCP/IP协议
[SQL] sql32 sets the last of all employees in the employees table_ Name and first_ Name splicing