首页 > mysql语句用了子表 索引无效了 我该怎么建立索引呢?

mysql语句用了子表 索引无效了 我该怎么建立索引呢?

PRIMARY KEY (id),
KEY create_time (create_time),
KEY usertype (usertype,userid),
KEY create_time_2 (create_time,usertype,userid)

explain select * from (select * from t_demand order by create_time)as tmp where usertype =4 group by userid\G

*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table:
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 282
Extra: Using where; Using temporary; Using filesort
*************************** 2. row ***************************
id: 2
select_type: DERIVED
table: t_demand
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 282
Extra: Using filesort
2 rows in set (0.05 sec)

这条语句意见建立了对应都索引和联合索引,但是就是没有用上索引,我该怎么优化,才能试用上呢?求大神们帮忙

【热门文章】
【热门文章】