我有这样的疑问:
SELECT city.id, city.country_id, localization.lang , localization.name, ... some other fields ...
FROM city city
LEFT OUTER JOIN city_localization localization ON ( localization.city_id = city.id )
WHERE city.country_id = '196' AND localization.lang = 'en'
ORDER BY localization.name
“city”表架构:
“city_localization”表架构:
解释输出:
如何避免使用filesort和临时?
答案 0 :(得分:1)
您需要为localization.city_id
创建一个索引,为localization.name
创建另一个索引(您目前还有一个也包含localization.lang
)。
如果您要检索大量行,则可能需要从选择中删除city.country_id
和localization.lang
,毕竟您已经拥有这些值。