Optimize GROUP BY a ORDER BY b in mysql

The following query took 150 ms on a dataset of a few thousand rows, even though there were indexes on companies.id, companies.name and people.company_id. SELECT companies.id, count(people.id) FROM companies LEFT JOIN people on companies.id = people.company_id GROUP BY companies.id ORDER BY companies.name Explain revealed “Using index; Using temporary”.┬áTurns out that mysql can only use a [...]