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兩個表全是全表掃描

相關文章
相關標籤/搜索