求高人指点,关于慢日志里Rows_examined的疑问
有一张正文表,字段有d_id(文档id),createdate(创建日期),createtime(创建时间),title(标题)等CREATE TABLE `content` (`d_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`createdate` date NOT NULL DEFAULT '0000-00-00',
`createtime` time NOT NULL DEFAULT '00:00:00',
`title` text,
……
PRIMARY KEY (`d_id`),
KEY `createdate` (`createdate`,`createtime`),
) ENGINE=MyISAM
执行以下sqlselect * from content where title like '出版%' and createdate = '2011-11-29' order by d_id desc limit 1 ;
慢日志:
# Query_time: 17.311505Lock_time: 0.000670 Rows_sent: 0Rows_examined: 1972413
为什么Rows_examined是1972413这么大?符合createdate = '2011-11-29'条件的记录仅有3000多条阿?
是索引建的有问题么?
是不应该做createdate和createtime的联合索引么?
实在是不解。求高人指点! 把explain select * from content where title like '出版%' and createdate = '2011-11-29' order by d_id desc limit 1 ; 的结果贴一下。 mysql> explain select * from content where title like '出版%' and createdate = '2011-11-29' order by d_id desc limit 1 ;
+----+-------------+---------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type| possible_keys | key | key_len | ref| rows | Extra |
+----+-------------+---------+-------+---------------+---------+---------+------+------+-------------+
|1 | SIMPLE | content | index | createdate | PRIMARY | 4 | NULL |131 | Using where |
+----+-------------+---------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.00 sec) 很明显没有用到你的createdate 索引,你的content 表的记录应该就是1972413行吧! 是因为createdate和createtime做了联合索引,而createdate没有做单独索引吧?我再加一个createdate的单独索引就好了吧? 还是全表检索!为啥阿 回复 5# kookies
不是的,你的createdate已经在索引的最左边,现在你再加一个单独的索引也用不到的
页:
[1]