Mysql“;“发送数据”;太久
我有32000条记录的表格Mysql“;“发送数据”;太久,mysql,Mysql,我有32000条记录的表格com\u news 表格com\u新闻 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(1
com\u news
表格com\u新闻
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
表中缺少索引 因此,这里您可以做些什么来提高性能
alter table com_news add index stat_ts_idx (status,ts);
现在,请确保在应用索引之前备份了表和数据
此外,你应该经常检查查询的解释计划,这将告诉你很多
嗯,在(状态,ts)[或者是(状态,ts);我永远记不起来]上建立索引可能会有帮助。谢谢!查询将更快地发送数据0.005353