半年时间,带你从后端走向全栈
从后端到全栈CTO,我花了10年,这10年浓缩成了120多个小时,个人10年,你或许只须要半年,我但愿
你比我幸运,少一些投石问路式的摸索,以更快的速度成为能胜任更高职位,更受市场青睐的全栈工程师
函數操做
對條件字段作函數操做走不了索引。html
select * from t1 where date© =‘2019-05-21’;
優化:改为範圍查询后端
select * from t1 where c>=‘2019-05-21 00:00:00’ and c<=‘2019-05-21 23:59:59’;
隱式轉換
操做符與不一样類型的操做對象一同運用時,就會發做類型轉換以使操做兼容。ide
select user_name,tele_phone from user_info where tele_phone =11111111111; / tele_phone varchar /
實践會作函數操做:htm
select user_name,tele_phone from user_info where cast(tele_phone as singed int) =11111111111;
優化:類型統一索引
select user_name,tele_phone from user_info where tele_phone =‘11111111111’;
含糊查询
通配符在前面get
select * from t1 where a like ‘%1111%’;
優化:含糊查询必需包含條件字段前面的值it
select * from t1 where a like ‘1111%’;
範圍查询
範圍查询數據量太多,需求回表,于是不走索引。io
select * from t1 where b>=1 and b <=2000;
優化:下降單次查询範圍,分屢次查询。(實践可能速度沒得快太多,倡議走索引)ast
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)
計算操做
即使是简單的計算class
explain select * from t1 where b-1 =1000;
優化:將計算操做放在等號後面
explain select * from t1 where b =1000 + 1;