我在索引这个左连接时遇到问题:
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
我有以下索引:
Comments -> keyname (postid) - postid, active, 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 | |
+----+-------------+----------+------+---------------+--------+---------+-------------+------+---------------------------------+
我该如何解决这个问题,这样我就不会“使用临时;使用文件排序”?