我有一个有点复杂的查询,大约有 100K 行。
查询在 SQL Server Express 中运行 13 秒(在我的开发盒上运行)
具有相同索引和表的相同查询需要超过 15 分钟才能在 MySQL 5.1 上运行(在我的生产机器上运行 - 功能更强大,并且经过 100% 资源测试)有时查询会因内存不足错误而导致机器崩溃。
我在 MySQL 中做错了什么?为什么需要这么长时间?
select e8.*
from table_a e8
inner join (
select max(e6.id) as id, e6.category, e6.entity, e6.service_date
from (
select e4.*
from table_a e4
inner join (
select max(e2.id) as id, e3.rank, e2.entity, e2.provider_id, e2.service_date
from table_a e2
inner join (
select min(e1.rank) as rank, e1.entity, e1.provider_id, e1.service_date
from table_a e1
where e1.site_id is not null
group by e1.entity, e1.provider_id, e1.service_date
) as e3
on e2.rank= e3.rank
and e2.entity = e3.entity
and e2.provider_id = e3.provider_id
and e2.service_date = e3.service_date
and e2.rank= e3.rank
group by e2.entity, e2.provider_id, e2.service_date, e3.rank
) e5
on e4.id = e5.id
and e4.rank= e5.rank
) e6
group by e6.category, e6.entity, e6.service_date
) e7
on e8.id = e7.id and e7.category = e8.category