0

我有一个查询:

SELECT last_name, uid, full_name, user_name, email_address, user_photo,
       count(checkin_id) as c_c, max(created_at) as mdi
FROM activity
INNER JOIN users on checkin.user_id = users.uid
INNER JOIN friends on (friends.friend_id = checkin.user_id)
WHERE friends.user_id = '1' and item_id = '2025' and
      created_at >= DATE_SUB('2013-07-10 03:16:24', INTERVAL 30 DAY) and
      venue_id = '5622' and is_approved = 1
GROUP by activity.user_id
ORDER by c_c desc LIMIT 30;

此查询的目标是让所有在过去 30 天内与您完成相同活动的朋友进入相同的项目。

当我进行解释时,我在checkin表上得到一个 index_merge,用于以下索引:

venue_id_2 -> venue_id
item_id -> item_id

查询时间为:

# Query_time: 6.710844  Lock_time: 0.033860 Rows_sent: 0  Rows_examined: 16

不知道为什么只有 16 行的东西需要 6.7 秒。有任何想法吗?索引应该在这里?

4

0 回答 0