查询部分:
FROM
pm_data AS pmdata
LEFT JOIN messages as pm
ON pmdata.msg_id = pm.msg_id
LEFT JOIN users as usr
ON (usr.uid = pm.reciever_id || usr.uid = pm.sender_id)
WHERE
(
pmdata.sender_id = 541839243781
AND
pmdata.sender_isdeleted = 1
)
OR
(
pmdata.reciever_id = 541839243781
AND
pmdata.reciever_isDeleted = 1
)
ORDER BY pm.created_at DESC
目前我只添加了
index1(msg_id)
index2(sender_isDeleted)
最佳答案
仅对于此查询,有用的索引是:
pmdata(sender_id)
pmdata(reciever_id)
消息(msg_id)
用户(uid)
该查询不需要您提到的内容:
index1(msg_id)
index2(sender_isDeleted)