对于下一个查询:
SELECT m.id, m.body, m.poster, m.added
FROM messages m
WHERE ((m.poster_id = '11' OR m.poster_id = '22') AND (m.to = '11' OR m.to = '22'))
ORDER BY m.id DESC
LIMIT 10
什么是最好的索引?
我试过 (poster_id, to, id) - 大约 1.5s 试过 (poster_id, to) - 大约 0,10s
如果我删除订单,我会得到 0.00s
问题是即使在空结果上,使用 ORDER BY,我仍然得到 0,09s。
解释:
+----+-------------+-------+-------+------------------------------+-----------------+---------+------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+------------------------------+-----------------+---------+------+------+-----------------------------+
| 1 | SIMPLE | m | range | posterid_to_idx,to,poster_id | posterid_to_idx | 8 | NULL | 4 | Using where; Using filesort |
+----+-------------+-------+-------+------------------------------+-----------------+---------+------+------+-----------------------------+
谢谢