, :
3 4 . 2 - , outcome < 2 , on (battle_type, result, username) .
Assuming this outcomeis an enumeration 0,1,2,3..., you can change the range condition to equality comparison and benefit from the index (battle_type, result, username):
SELECT username, SUM( outcome ) AS wins, COUNT( * ) - SUM( outcome ) AS losses
FROM tblBattleHistory
WHERE battle_type = 0 AND outcome IN (0, 1)
GROUP BY username
ORDER BY wins DESC , losses ASC , username ASC
LIMIT 0 , 50
If outcomeit is not an enumeration, then the on (battle_type, result) index will act. Index on (battle_type) is now only an excess, since it battle_typeis a prefix in a composite index.
source
share