JavaEE在線就業班2.0【最新升級版】

download:JavaEE在線就業班2.0【最新升級版】

函數操做
對條件字段作函數操做走不了索引。html

select * from t1 where date© =‘2019-05-21’;
優化:改爲範圍查詢ide

select * from t1 where c>=‘2019-05-21 00:00:00’ and c<=‘2019-05-21 23:59:59’;
隱式轉換
操做符與不一樣類型的操做對象一同運用時,就會發做類型轉換以使操做兼容。htm

select user_name,tele_phone from user_info where tele_phone =11111111111; / tele_phone varchar /
實踐會作函數操做:索引

select user_name,tele_phone from user_info where cast(tele_phone as singed int) =11111111111;
優化:類型統一get

select user_name,tele_phone from user_info where tele_phone =‘11111111111’;
含糊查詢
通配符在前面it

select * from t1 where a like ‘%1111%’;
優化:含糊查詢必需包含條件字段前面的值io

select * from t1 where a like ‘1111%’;
範圍查詢
範圍查詢數據量太多,需求回表,於是不走索引。ast

select * from t1 where b>=1 and b <=2000;
優化:下降單次查詢範圍,分屢次查詢。(實踐可能速度沒得快太多,倡議走索引)class

select from t1 where b>=1 and b <=1000;
show profiles;
±---------±-----------±-----------------------------------------+
| Query_ID | Duration | Query |
±---------±-----------±-----------------------------------------+
| 1 | 0.00534775 | select
from t1 where b>=1 and b <=1000 |
| 2 | 0.00605625 | select * from t1 where b>=1 and b <=2000 |
±---------±-----------±-----------------------------------------+
2 rows in set, 1 warning (0.00 sec)
計算操做
即使是簡單的計算thread

explain select * from t1 where b-1 =1000;
優化:將計算操做放在等號後面

explain select * from t1 where b =1000 + 1;

相關文章
相關標籤/搜索