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会慢到卡死?应该如何改进?