数据库优化

  1. 应尽量避免在 where 子句中使用 or 来连接条件,否则将导致引擎放弃使用索引而进行全表扫描,如:
select id from t where num=10 or num=20

可以这样查询:

select id from t where num=10union allselect id from t where num=20

 

2.应尽量避免在 where 子句中对字段进行表达式操作,这将导致引擎放弃使用索引而进行全表扫描。如:

select id from t where num/2=100

应改为:

select id from t where num=100*2

不要在 where 子句中的“=”左边进行函数、算术运算或其他表达式运算,否则系统将不能正确使用索引。



来自:https://mp.weixin.qq.com/s/L1E3MJYeUpmNn4VuGMY65Q

posted @ 2020-11-19 16:51  乌柒柒  阅读(60)  评论(0编辑  收藏  举报