当前位置:网站首页>SQL语句简单优化
SQL语句简单优化
2022-04-23 05:31:00 【Netfishless】
总结笔记
1、避免使用‘*’,直接使用列名字
在解析过程中,会将‘*’一次转化为所有的列名,并通过查询字典完成,消耗更多时间。
2、多表查询时,尽量使用表的别名
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Q2VSZkFk-1650542099215)(https://secure2.wostatic.cn/static/ohQBsP5YJUwjw4XMBSNZtL/image.png)]](/img/24/2df24de28869f4b4623177124a5c07.png)
可以更加精确的定义到哪张表的哪个字段,也避免相同列名的产生的问题。
3、Where子句中,把能快速缩小查询范围的语句放在最右边
因为where子句中的语句,是按照从右往左的顺序执行。

先把“=30”的找到,快速缩小了范围,然后再已经“=30”的范围里面找“>10”的范围。
4、使用“≥”代替“>”

如果使用“>3”,第一个找到的是3,然后依次比较比3大的数据,但第一个找到的3对结果没有任何作用。
当使用“≥4”时,会先找到4,然后再依次比较比4大的数据,此时4已经是正确答案之一
5、用TRUNCATE代替DELETE
DELETE操作比较安全,因为它删除之前,会先把删除内容放到回滚段中,如果误删可以恢复。
TRUNCATE是把数据直接删除掉,所以当确定数据一定会删除时,可以直接使用TRUNCATE,执行速度更快。
6、多实用COMMIT
当使用COMMIT后,会释放一些资源。

7、避免在索引列上使用函数

当sal使用了*2后,sal上的索引不会生效,还是会全表查询。
参考链接
版权声明
本文为[Netfishless]所创,转载请带上原文链接,感谢
https://blog.csdn.net/ClaireSy/article/details/124330120
边栏推荐
- Box collapse and margin collapse
- MySQL series - install MySQL 5.6.27 on Linux and solve common problems
- Xiuxian real world and game world
- Watch depth monitoring mode
- Basic knowledge of redis
- !!!!!!!!!!!!!!!!!!
- Error handling mechanism of the strongest egg framework in history
- Data bus realizes the communication between brother components
- Camera imaging + homography transformation + camera calibration + stereo correction
- Necessity of selenium preloading cookies
猜你喜欢

CPT 104_TTL 09

npm升级后问题,慌得一批

selenium預先加載cookie的必要性

Excel 2016 cannot open the file for the first time. Sometimes it is blank and sometimes it is very slow. You have to open it for the second time

Hongji | how does HR carry out self change and organizational change in the digital era?

弘玑|数字化时代下,HR如何进行自我变革和组织变革?

Create cells through JS (while loop)

(十一)vscode代码格式化配置

Intel SGX preliminary learning and understanding notes (continuously updated)

Create process memory management copy_ Mm - processes and threads (IX)
随机推荐
Watch depth monitoring mode
Use of ES6 array
Uniapp hot update with progress bar
Laravel routing job
MySQL series - install MySQL 5.6.27 on Linux and solve common problems
Deep learning object detection
egg测试的知识大全--mock、superTest、coffee
Requirements for SQL server to retrieve SQL and user information
Various situations of data / component binding
Use pagoda + Xdebug + vscode to debug code remotely
node中的redis使用--ioredis
Several examples of pointer transfer, parameter transfer, value transfer, etc
可執行程序執行流程
[triangle Yang Hui triangle printing odd even cycle JS for break cycle]
catkin_ What did package do
JSON.
Create process memory management copy_ Mm - processes and threads (IX)
Data bus realizes the communication between brother components
狼叔来找翻译人员了--plato--持续翻译中.....
QT displays the specified position and size of the picture