通过联合索引优化MYSQL慢查询 一、慢SQL分析 慢SQL如下 SELECT SUM(t.amount) as amount FROM (SELECT game_id,room_id,is_robot,amount,record_time FROM t_statements_logs WHERE game_id = 30 AND is_robot = 0 ORDER BY record_time DESC)t GROUP BY t.room_id ORDER BY t.record_time DESC LIMIT 20; 执行时间通常在1S以上 表索引情况如下: 查询执行计划 EXPL