我有2个SQL查询,我试图优化以删除"使用where;使用临时;使用filesort"。
第一次查询:
SELECT DISTINCT M.pseudo , M.id as id , CM.send FROM `chat_messages` CM
inner JOIN `uniic_member` M
ON ((CM.`receiver_id` = 22141 AND M.id=CM.sender_id and CM.`status` != 2)
OR (CM.`sender_id` = 22141 AND M.id=CM.receiver_id AND CM.`status` != 1))
GROUP BY pseudo ORDER BY send DESC;
第二个查询:
SELECT e.*, p.filename AS photo, m.pseudo AS pseudo, m.gender AS gender
FROM uniic_mailbox AS e
LEFT JOIN uniic_member AS m ON m.id = e.sender_id LEFT JOIN uniic_photos AS p
ON (m.id = p.member_id AND p.main_photo = 1) WHERE e.status IN (0,1)
AND e.member_id = 2248 AND e.sender_id
NOT IN (SELECT ban_id FROM uniic_blacklist WHERE member_id = 2248)
AND e.created_at = (SELECT MAX(created_at) FROM uniic_mailbox
WHERE status IN (0,1) AND member_id = 2248 AND sender_id = e.sender_id LIMIT 1)
GROUP BY e.id ORDER BY e.created_at DESC LIMIT 0 , 11;
请告诉我有什么方法可以修复"使用where;使用临时;使用filesort"并改善此查询的性能?