索引此查询

时间:2012-03-15 06:46:44

标签: mysql sql indexing

查询的一部分:

    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

目前我只添加了

  • 索引1(MSG_ID)
  • 索引2(sender_isDeleted)

1 个答案:

答案 0 :(得分:1)

仅对于此查询,有用的索引为:

  • PMDATA(SENDER_ID)
  • PMDATA(reciever_id)
  • 消息(MSG_ID)
  • 用户(UID)

此查询不需要您提到的内容:

  • 索引1(MSG_ID)
  • 索引2(sender_isDeleted)