2014-05-19 58 views
0

我有表com_news與32000記錄。Mysql「發送數據」太長

com_news

CREATE TABLE IF NOT EXISTS `com_news` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`ts` int(11) NOT NULL, 
`title` varchar(255) NOT NULL, 
`text` longtext NOT NULL, 
`id_user` int(11) NOT NULL DEFAULT '0', 
`id_catalog` int(11) NOT NULL DEFAULT '0', 
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '0-off,1-on', 
`window_title` varchar(255) DEFAULT NULL, 
`meta_keywords` varchar(255) DEFAULT NULL, 
`meta_description` text, 
`source` varchar(255) DEFAULT NULL, 
`img` int(11) NOT NULL DEFAULT '0', 
`to_twitter` tinyint(4) NOT NULL DEFAULT '0', 
PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=32719 ; 

查詢

SELECT COUNT(*) FROM `com_news` WHERE status=1 AND ts>=1398888007 

檔案

starting 0.000009 
checking query cache for query 0.000027 
Opening tables 0.000014 
System lock 0.000003 
Table lock 0.000016 
init 0.000015 
optimizing 0.000009 
statistics 0.000009 
preparing 0.000008 
executing 0.000004 
Sending data 0.517773 
end 0.000013 
query end 0.000003 
freeing items 0.000025 
storing result in query cache 0.000006 
logging slow query 0.000002 
cleaning up 0.000003 

爲什麼發送數據太長?

Apache/2.2.15 (CentOS) 
MySQL: 5.1.73 
+1

那麼,在索引(狀態,TS)[或者是(TS,狀態);我永遠不會記得]可能會有所幫助。 – Strawberry

回答

1

您缺少表格中的索引。

所以在這裏,你能做些什麼來提高性能

alter table com_news add index stat_ts_idx (status,ts); 

現在,請確保您的表和數據的備份應用索引之前。

此外,你應該總是檢查查詢的解釋計劃,這將告訴你很多。

http://dev.mysql.com/doc/refman/5.0/en/explain.html

+0

謝謝!查詢變得更快 發送數據\t 0.005353 –