免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 28537 | 回复: 6
打印 上一主题 下一主题

求高人指点,关于慢日志里Rows_examined的疑问 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-02 09:37 |只看该作者 |倒序浏览
有一张正文表,字段有d_id(文档id),createdate(创建日期),createtime(创建时间),title(标题)等
  1. CREATE TABLE `content` (
  2.   `d_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  3.   `createdate` date NOT NULL DEFAULT '0000-00-00',
  4.   `createtime` time NOT NULL DEFAULT '00:00:00',
  5.   `title` text,
  6.   ……
  7.   PRIMARY KEY (`d_id`),
  8.   KEY `createdate` (`createdate`,`createtime`),
  9. ) ENGINE=MyISAM
复制代码
执行以下sql
  1. select * from content where title like '出版%' and createdate = '2011-11-29' order by d_id desc limit 1 ;
复制代码
慢日志:
# Query_time: 17.311505  Lock_time: 0.000670 Rows_sent: 0  Rows_examined: 1972413

为什么Rows_examined是1972413这么大?符合createdate = '2011-11-29'条件的记录仅有3000多条阿?
是索引建的有问题么?
是不应该做createdate和createtime的联合索引么?
实在是不解。求高人指点!

论坛徽章:
0
2 [报告]
发表于 2011-12-02 09:46 |只看该作者
把explain select * from content where title like '出版%' and createdate = '2011-11-29' order by d_id desc limit 1 ; 的结果贴一下。

论坛徽章:
0
3 [报告]
发表于 2011-12-02 09:51 |只看该作者
  1. mysql> explain select * from content where title like '出版%' and createdate = '2011-11-29' order by d_id desc limit 1 ;
  2. +----+-------------+---------+-------+---------------+---------+---------+------+------+-------------+
  3. | id | select_type | table   | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
  4. +----+-------------+---------+-------+---------------+---------+---------+------+------+-------------+
  5. |  1 | SIMPLE      | content | index | createdate    | PRIMARY | 4       | NULL |  131 | Using where |
  6. +----+-------------+---------+-------+---------------+---------+---------+------+------+-------------+
  7. 1 row in set (0.00 sec)
复制代码

论坛徽章:
0
4 [报告]
发表于 2011-12-02 10:16 |只看该作者
很明显没有用到你的createdate 索引,你的content 表的记录应该就是1972413行吧!

论坛徽章:
0
5 [报告]
发表于 2011-12-02 10:51 |只看该作者
是因为createdate和createtime做了联合索引,而createdate没有做单独索引吧?我再加一个createdate的单独索引就好了吧?

论坛徽章:
0
6 [报告]
发表于 2011-12-02 11:33 |只看该作者
还是全表检索!为啥阿

论坛徽章:
0
7 [报告]
发表于 2011-12-02 11:34 |只看该作者
回复 5# kookies


    不是的,你的createdate已经在索引的最左边,现在你再加一个单独的索引也用不到的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP