我正在尝试从多个表中提取数据,当我使用 ORDER BY 日期时间字段时,它会在至少 10 秒后返回结果,但是如果我在没有 ORDER BY 的情况下执行相同的查询,那么它会在 2 秒内返回结果。
这是我当前的查询
SELECT
ph.call_subject AS callSubject,
ac.account_name AS accountName,
DATE_FORMAT(ph.trigger_on, "%c/%e/%Y %h:%i %p") AS triggerOn,
ind.name AS industry,
cc.call_code_name AS callCode
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-11-19 00:00:00' AND '2013-03-19 23:59:59'
ORDER BY ph.trigger_on ASC LIMIT 0,1000
以下字段均为 INT(11) UNSIGNED 类型
ph.account_id
ac.account_id
ind.industry_id
ac.industry_id
ph.call_code_id
cc.call_code_id
ph.owner_id
以下字段均为 tinyint(1) 类型
ac.status
ph.status
ac.do_not_call
此字段是日期时间类型
ph.trigger_on
请注意,accounts 有 300K 条记录,phone_calls 有 500 万条记录。我该怎么做才能更快地执行此 ORDER BY?请注意,我的所有 where 子句字段、我的所有 ON 子句和 ph.trigger_on 都已编入索引。我使用的是 InnoDB 存储引擎而不是 MyIsam。
谢谢