How to optimise this MySQL query? Millions of Rows
问题 I have the following query: SELECT analytics.source AS referrer, COUNT(analytics.id) AS frequency, SUM(IF(transactions.status = 'COMPLETED', 1, 0)) AS sales FROM analytics LEFT JOIN transactions ON analytics.id = transactions.analytics WHERE analytics.user_id = 52094 GROUP BY analytics.source ORDER BY frequency DESC LIMIT 10 The analytics table has 60M rows and the transactions table has 3M rows. When I run an EXPLAIN on this query, I get: +------+--------------+-----------------+--------+---