今天發現網站變慢,查了一下原因
1.量大需限定範圍:
資料大約50萬筆,抓最近5筆資料,多加了範圍限制快了10倍
$sql = "SELECT TOP(5) * FROM page_log pl ORDER BY time DESC"; $s = microtime(time); $result = $this->db->queryAll($sql); $e = microtime(time); echo $e - $s;
結果:0.605秒
$sql = "SELECT TOP(5) * FROM page_log pl WHERE time > '20140807000000' ORDER BY time DESC"; $s = microtime(time); $result = $this->db->queryAll($sql); $e = microtime(time); echo $e - $s;
結果:0.07秒
沒有留言:
張貼留言