MySQL優化細節:
1.適當使用索引
2.避免like等正則表達式的使用。如將:
select id from table where id like “98___”
//替換爲:
select id from table where id > 9800
3.將大表拆分爲小表,減小表的列數
4.使用join,而不是嵌套or笛卡兒積
5.拆分delete。因爲一個大的delete可能要很久,由於DB內部的鎖機制,會使DB幾十秒內無法響應,於是使用分批的方式,用limit限制每次delete的個數。
mysql_query("delete * from student where age <= 20");
//替換爲:
while(1) {
mysql_query("delete * from student where age >= 20 limit 1000");
if (mysql_affected_rows() == 0)
break;
sleep(50);
}
6.少使用select *,用什麼就選什麼
7.使用臨時表。當同一個SQL查詢要使用多次時,建立一個臨時表用來存儲結果。
select * from student left join course
INTO TEMP temp_table
//這樣我們再使用這個查詢時,可以:
select * from temp_table
8.大數據分頁查詢
search(vtype, id)建立複合索引,第一位的是where判斷的索引,第二位是主鍵,如:
//設置複合索引
search(vtype, id)
//分頁查詢,從第90000條開始的10個記錄
select id from collect where vtype=1 limit 90000,10;
MySQL語句:
http://blog.csdn.net/u011225629/article/details/46698969
MySQL線程池:
http://blog.csdn.net/u011225629/article/details/46721907
MySQL索引詳解:
http://blog.csdn.net/u011225629/article/details/46754071
MySQL索引優化:
http://blog.csdn.net/u011225629/article/details/46754093
MySQL大數據建表優化:
http://blog.csdn.net/u011225629/article/details/46775621
MySQL大數據查詢優化:
http://blog.csdn.net/u011225629/article/details/46775727
MySQL大數據分頁查詢優化:
http://blog.csdn.net/u011225629/article/details/46775815