【发布时间】:2011-04-23 12:28:00
【问题描述】:
这些 sql 查询的唯一区别是 record_id 参数(这是我对整个结果集进行分页的方式)。桌子是myisam。第一个查询执行良好,第二个查询非常慢。知道为什么会这样吗?
这个查询工作正常
explain select r.record_id, r.oai_datestamp, r.format_id, r.status, x.xml, max(u.date_updated) as date_updated
from marcnormalization.records r,
marcnormalization.records_xml x,
marcnormalization.record_updates u
where r.record_id = x.record_id
and (r.record_id > 1802000 or 1802000 is null)
and r.record_id = u.record_id
and (u.date_updated > '1960-10-19 10:18:52.0' or '1960-10-19 10:18:52.0' is null)
and u.date_updated <= '2010-10-07 10:18:52.0'
group by u.record_id
order by u.record_id
limit 1000;
这个查询超级慢(创建一个临时表)
explain select r.record_id, r.oai_datestamp, r.format_id, r.status, x.xml, max(u.date_updated) as date_updated
from marcnormalization.records r,
marcnormalization.records_xml x,
marcnormalization.record_updates u
where r.record_id = x.record_id
and (r.record_id > 2202000 or 2202000 is null)
and r.record_id = u.record_id
and (u.date_updated > '1960-10-19 10:18:52.0' or '1960-10-19 10:18:52.0' is null)
and u.date_updated <= '2010-10-07 10:18:52.0'
group by u.record_id
order by u.record_id
limit 1000;
更新:我已经通过更改从
解决了我的问题group by u.record_id
order by u.record_id
到
group by r.record_id
order by r.record_id
所以,现在这是一个有争议的问题,但我仍然对最初的问题感到好奇。
【问题讨论】: