这个查询为什么没有使用索引?
时间:2011-09-13
来源:互联网
表结构:
SQL code
查询语句:
SQL code
排序没有使用索引,但是rank定义索引了,这是怎么回事?
SQL code
Create Table: CREATE TABLE `sina_weibo_status` ( `sid` bigint(20) NOT NULL DEFAULT '0', `text` varchar(255) DEFAULT NULL, `source` varchar(255) DEFAULT NULL, `truncated` int(1) DEFAULT NULL , `thumbnail_pic` varchar(255) DEFAULT NULL, `bmiddle_pic` varchar(255) DEFAULT NULL, `original_pic` varchar(255) DEFAULT NULL, `uid` bigint(20) DEFAULT NULL COMMENT, `retweeted_status` bigint(20) DEFAULT '0', `in_reply_to_status_id` bigint(20) DEFAULT NULL, `created_at` datetime DEFAULT NULL, `aid` int(10) NOT NULL COMMENT, `category` int(10) NOT NULL, `status` tinyint(4) NOT NULL DEFAULT '0', `retweeted_num` int(11) NOT NULL DEFAULT '0', `rank` double NOT NULL DEFAULT '0', `created_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_date` datetime DEFAULT NULL, PRIMARY KEY (`sid`), KEY `sina_weibo_status_category_fk1` (`category`), KEY `sina_weibo_status_rank_index` (`rank`), KEY `sina_weibo_status_updated_date_index` (`updated_date`), KEY `sina_weibo_status_uid` (`uid`), KEY `sina_weibo_status_retweeted_status` (`retweeted_status`), CONSTRAINT `sina_weibo_status_ibfk_1` FOREIGN KEY (`category`) REFERENCES `category` (`id`) ON DELETE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8
查询语句:
SQL code
mysql> explain SELECT * FROM `sina_weibo_status` `t` WHERE ((category='11') AND (status='0')) AND (retweeted_status='0') ORDER BY rank desc LIMIT 20 \G; *************************** 1. row *************************** id: 1 select_type: SIMPLE table: t type: index_merge possible_keys: sina_weibo_status_category_fk1,sina_weibo_status_retweeted_status key: sina_weibo_status_category_fk1,sina_weibo_status_retweeted_status key_len: 4,9 ref: NULL rows: 275502 Extra: Using intersect(sina_weibo_status_category_fk1,sina_weibo_status_retweeted_status); Using where; Using filesort
排序没有使用索引,但是rank定义索引了,这是怎么回事?
作者: zcy_dr 发布时间: 2011-09-13
你的category、status、retweeted_status有多少种值,在
category、status、retweeted_status、rank上建立复合索引试试
category、status、retweeted_status、rank上建立复合索引试试
作者: wwwwb 发布时间: 2011-09-13
创建索引如下。
create index xxx on `sina_weibo_status`( category, status, retweeted_status, rank);
另外它也利用了索引,并不是没用。 intersect(sina_weibo_status_category_fk1,sina_weibo_status_retweeted_status);
create index xxx on `sina_weibo_status`( category, status, retweeted_status, rank);
另外它也利用了索引,并不是没用。 intersect(sina_weibo_status_category_fk1,sina_weibo_status_retweeted_status);
作者: ACMAIN_CHM 发布时间: 2011-09-13
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28