【求助】关于MYSQL关联索引的走向问题及优化方案
时间:2011-11-30
来源:互联网
explain select * from A ,B where a.userid = b.reuserid and b.userid = 13 and a.type=107 order by a.add_time desc limit 1,30;
| id | select_type | table | type | key | key_len | ref | rows | Extra
| 1 | SIMPLE | b | ref | userid | 4 | const | 6630 | Using temporary;
| 1 | SIMPLE | a | ref | userid_2 | 10 | b.reuserid,const | 5 | Using where
数据量:
A表 18w
B表 50w
索引:
A表 联合索引:(userid,add_time)
B表 联合索引:(userid,reuserid) 单独索引 userid 、reuserid
表及字段含义:
A表 :用户动态
B表 :用户关注情况表
userid :用户ID
reuserid:被关注用户ID
SQL含义:
查询13号会员关注的人的最近30条动态。
explain出来的结果,索引的走向是:
1.B表的 userid
2.A表的 userid,add_time
哪位牛人解释一下为什么这个SQL会慢到卡死?应该如何改进?
| id | select_type | table | type | key | key_len | ref | rows | Extra
| 1 | SIMPLE | b | ref | userid | 4 | const | 6630 | Using temporary;
| 1 | SIMPLE | a | ref | userid_2 | 10 | b.reuserid,const | 5 | Using where
数据量:
A表 18w
B表 50w
索引:
A表 联合索引:(userid,add_time)
B表 联合索引:(userid,reuserid) 单独索引 userid 、reuserid
表及字段含义:
A表 :用户动态
B表 :用户关注情况表
userid :用户ID
reuserid:被关注用户ID
SQL含义:
查询13号会员关注的人的最近30条动态。
explain出来的结果,索引的走向是:
1.B表的 userid
2.A表的 userid,add_time
哪位牛人解释一下为什么这个SQL会慢到卡死?应该如何改进?
作者: scorpio1 发布时间: 2011-11-30
create index x on A (type,add_time);
作者: ACMAIN_CHM 发布时间: 2011-11-30
scorpio1
'截至2011-11-30 17:07:06 用户结帖率25.00%
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html
8、如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖
'截至2011-11-30 17:07:06 用户结帖率25.00%
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html
8、如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖
作者: ACMAIN_CHM 发布时间: 2011-11-30
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28