0
我是一個db noob,有一個令人討厭的查詢需要超過30秒才能運行。我正在努力學習更多關於EXPLAIN的知識,並優化查詢,但無所適從。下面是該查詢:使用MySQL優化查詢EXPLAIN
SELECT
feed.*, users.username, smf_attachments.id_attach AS avatar,
games.name AS item_name, games.image, feed.item_id, u2.username AS follow_name
FROM feed
INNER JOIN following ON following.follow_id = feed.user_id AND following.user_id = 1
LEFT JOIN users ON users.id = feed.user_id
LEFT JOIN smf_members ON smf_members.member_name = users.username
LEFT JOIN smf_attachments ON smf_attachments.id_member = smf_members.id_member
LEFT JOIN games ON games.id = feed.item_id
LEFT JOIN users u2 ON u2.id = feed.item_id
ORDER BY feed.timestamp DESC
LIMIT 25
解釋結果:
您的表格中有多少條線? –
沒什麼太大的。遊戲大約是50k。用戶在20K左右。所有其他人都小得多。儘快發佈我的EXPLAIN結果,以便能夠正確格式化它們。 – madzilla