How to optimize MySQL “Order By Limit 1” in queries that join multiple tables?
问题 So I have a query like this: SELECT tablea.name, tablea.views from tablea inner join tableb on (tablea.id = tableb.id and tablea.balance > 0) order by tablea.views asc limit 1 However, the problem is that when I run it, it runs quite slow (4+ seconds). Interestingly, when the 'order by' clause is removed, while keeping the limit 1, it runs in 0.005 seconds (approx). Even more interestingly: when I don't join it to tableb, i.e.: SELECT tablea.name, tablea.views from tablea where tablea.balance