我有一个从许多表中提取的查询,但速度很慢,我想改进它。
SELECT
ph.phone_call_id AS id,
ph.call_subject AS callSubject,
ac.account_name AS accountName,
ph.trigger_on AS triggerOn,
ph.isAppointment,
ph.status,
ind.name AS industry,
cc.call_code_name AS callCode,
ac.account_id FROM phone_calls AS ph
INNER JOIN accounts AS ac ON ph.account_id = ac.account_id
INNER JOIN industries AS ind ON ind.industry_id = ac.industry_id
INNER JOIN call_codes AS cc ON ph.call_code_id = cc.call_code_id
WHERE
ac.status = 1 AND
ph.status = 1 AND
ph.owner_id = 1 AND
ac.do_not_call = 0 AND
ph.trigger_on BETWEEN '2012-10-09 00:00:00' AND '2013-04-09 23:59:59'
LIMIT 0,25
请注意,phone_Calls 表有大约 450 万条记录,帐户大约有 30 万条记录。
我现在有这样的索引
ph.trigger_on
ph.owner_id
ph.status
ac.status
ac.do_not_call
ac.account_id
这是我解释查询时得到的