我無法索引該左連接:MySQL - 如何索引這個左連接?
SELECT comments.id, comments.topid, comments.username, comments.body, comments.dt, comments.active, users.email
FROM comments
LEFT JOIN registered_users.users
ON comments.username = users.username
WHERE postid = 12 AND active = 1
ORDER BY id desc
我有指標:
評論 - >鍵名(帖子ID) - 帖子ID,活動,ID
用戶 - >鍵名(用戶名) - 用戶名
結果我找回的是:
+----+-------------+----------+------+---------------+--------+---------+-------------+------+---------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------+---------------+--------+---------+-------------+------+---------------------------------+
| 1 | SIMPLE | comments | ref | postid | postid | 5 | const,const | 116 | Using temporary; Using filesort |
| 1 | SIMPLE | users | ALL | NULL | NULL | NULL | NULL | 1 | |
+----+-------------+----------+------+---------------+--------+---------+-------------+------+---------------------------------+
我該如何解決這個問題,以免我「臨時使用;使用文件排序」?
但它使用的是索引。表現不好嗎? – Bohemian
現在的表現還算馬馬虎虎,但是我有一種感覺,因爲網站接收到更多的流量,這將是一個問題 –