下午好。
我有两个不同的查询执行完全相同的指令。但令我惊讶的是,我认为效率更高的那个比另一个更好,我一直试图理解这一点,但遗憾的是无法做到,有人能帮助我理解为什么吗?
提前非常感谢你。
原作(我认为会表现不佳):
SELECT *, competitions.name AS nome
FROM competitions
INNER JOIN areas ON areas.area_id = competitions.area_id
INNER JOIN seasons ON competitions.competition_id = seasons.competition_id
WHERE seasons.id IN (SELECT MAX(seasons.id)
FROM seasons
GROUP BY seasons.competition_id)
第二个(生成filesort并使用临时)
SELECT *, competitions.name as nome, MAX(seasons.id)
FROM seasons
INNER JOIN competitions ON competitions.competition_id = seasons.competition_id
INNER JOIN areas ON areas.area_id = competitions.area_id
GROUP BY seasons.competition_id