MySQL sql优化

一、where后条件语句须要注意的地方函数

(1)、要用索引索引

(2)、尽可能不要is null、!=、<>、in、not in、like等,会致使全表扫描it

(3)、“=”号左边尽可能不要用算数表达式或者函数等,会致使全表扫描。如select * from table where num/2 = 50,应改成num = 50*2table

(4)、效率

 

exist和in的区别select

select * from A where id in (select id from B)查询

select * from A where id exits (select id from B)tab

in适用于B表比A表小的状况ab

exits适用于A表比B表小的状况

对于not in和not exits

not exits的效率高,由于它的子查询会用到索引

not in两个表全是全表扫描

相关文章
相关标签/搜索