gpt4 book ai didi

php - 约束查询慢?

转载 作者:行者123 更新时间:2023-11-30 23:21:22 24 4
gpt4 key购买 nike

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

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

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

最佳答案

可能尝试使用 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 上的索引是什么?

关于php - 约束查询慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15291587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com