SELECT a.*, u.avatar, u.name, u.surname, u.username, COUNT(a.user1) AS cnt
FROM user_actions a,users u,following f
WHERE a.user1=u.user_id AND
a.user1=f.follower_id AND
f.user_id=159
GROUP BY a.user1, a.action, day(a.dt)
ORDER BY a.id DESC
LIMIT 7;
クエリには4.4909秒かかりました
テーブルuser_actionsのインデックス:
Action Keyname Type Unique Packed Column Cardinality Collation
Edit PRIMARY BTREE Yes No id 516094 A
Edit user1 BTREE No No user1 15639 A
Edit user2 BTREE No No user2 36863 A
Edit action BTREE No No action 16 A
Edit dt BTREE No No dt 516094 A
Edit group_index BTREE No No user1 20643 A
EXPLAIN SELECT a . * , u.avatar, u.name, u.surname, u.username, COUNT( a.user1 ) AS cnt
FROM user_actions a, users u, following f
WHERE a.user1 = u.user_id
AND a.user1 = f.follower_id
AND f.user_id =159
GROUP BY a.user1, a.action, day( a.dt )
ORDER BY a.id DESC
LIMIT 7
idselect_typeテーブルタイプpossible_keyskeykey_len ref rows Extra 1 SIMPLE f ref user_id、follower_id、for_actions for_actions 4const242インデックスの使用。一時的な使用; filesortの使用1SIMPLEa ref user1、group_index group_index 4 pictify_main.f.follower_id 25 1 SIMPLE u eq_ref PRIMARY PRIMARY 4pictify_main.a.user11ここでの使用