我的这个查询需要 45 秒才能执行。我对正在搜索的所有字段都有索引。
SELECT SQL_CALC_FOUND_ROWS g.app_group_id, g.id as g_id, p.`id` as form_id,
a.`user` as activity_user,a.`activity` as app_act ,a.*
FROM grouped g
INNER JOIN
(SELECT max(id) as id, app_group_id FROM grouped GROUP BY app_group_id) g1
ON g1.app_group_id = g.app_group_id AND g.id = g1.id
INNER JOIN form p
on p.id = g.id
INNER JOIN
(SELECT a.id, a.date_time, a.user, a.activity FROM log a) a
ON g.id = a.id
WHERE p.agname like '%blahblah%' and p.`save4later` != 'y'
and a.activity = 'APP Submitted' or a.activity = 'InstaQUOTE'
ORDER BY app_group_id DESC limit 0, 100
在我的解释中,它显示我正在使用临时使用;使用文件排序
索引是:
活动表:PRIMARY activity_id INDEX date_time INDEX id INDEX 活动 INDEX 用户
表格:PRIMARY id INDEX id_md5 INDEX dateadd INDEX dateu INDEX agent_or_underwriter INDEX
分组表:UNIQUE id INDEX app_group_id INDEX agent_or_underwriter save4later
非常感谢任何建议
非常感谢