1

我有这个需要时间的查询。下面是那个查询-

SELECT
    m1.mes_id,
    m1.body, 
    m1.subject,
    m1.frm_id AS mem_id,
    m1.date 
FROM 
    messages_system_new m1 
WHERE 
    m1.mes_id IN 
        (SELECT
            MAX(mn1.mes_id) AS mes_id 
        FROM messages_system_new mn1
        WHERE
            mn1.mem_id = '401' 
            AND mn1.frm_id != '401' 
            AND mn1.trashed_user NOT LIKE '%401%' 
            AND mn1.type = 'message' 
            AND mn1.folder = 'inbox' AND mn1.is_spam='N' 
        GROUP BY mn1.frm_id
        )

当被解雇时解释它的给予

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   PRIMARY m1  ALL (NULL)  (NULL)  (NULL)  (NULL)  6091    Using where
2   DEPENDENT SUBQUERY  mn1 ref mem_id,frm_id   mem_id  8   const   59  Using where; Using temporary; Using filesort

这是什么意思,我该如何改进查询?

4

1 回答 1

0

可能改用 JOIN 来尝试。像这样的东西

SELECT
    m1.mes_id,
    m1.body, 
    m1.subject,
    m1.frm_id AS mem_id,
    m1.date 
FROM messages_system_new m1 
INNER JOIN (SELECT mn1.frm_id  MAX(mn1.mes_id) AS mes_id 
        FROM messages_system_new mn1
        WHERE
            mn1.mem_id = '401' 
            AND mn1.frm_id != '401' 
            AND mn1.trashed_user NOT LIKE '%401%' 
            AND mn1.type = 'message' 
            AND mn1.folder = 'inbox' AND mn1.is_spam='N' 
        GROUP BY mn1.frm_id
        ) Sub1
ON m1.mes_id = Sub1.mes_id

messafes_system_new 上的索引是什么?

于 2013-03-08T10:32:47.017 回答