简体   繁体   中英

indexing this query

Part of query:

    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

at the moment i have only added

  • index1(msg_id)
  • index2(sender_isDeleted)

For this query only, useful indexes are:

  • pmdata(sender_id)
  • pmdata(reciever_id)
  • messages(msg_id)
  • users(uid)

This query does not need what you mentioned:

  • index1(msg_id)
  • index2(sender_isDeleted)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM