数据库的优化需要

1.一般在Where语句后面使用了null会导致索引查询失效。例如(where name is null;) 用0代替

2.<>或!=也会导致索引失效,例如(where name<>13);用name>13 and name<13

3.or也会导致索引查询失效,select name from employ where id=1 union all select name from employ where id =2

4.in not in也尽量少用,同样会导致索引失效,可以改成betweende 形式

5.like同上面一样也会导致索引失效

6.尽量不要对where后面的字段进行表达式操作,例如:where age/2>13;应该改成where age >13*2的形式

7.where substring(name,1,3)='abc'没有where name like 'abc%'更高效,带有函数的操作比较慢

8.很多时候用 exists 代替 in 是一个好的选择: 

select num from a where num in(select num from b)	
用下面的语句替换:	
select num from a where exists(select 1 from b where num=a.num)	

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值