I have a table with these fields: userid, logintime, birthdate
I need to get ALL users between birthdate X and Y ordered with the most recently logged in first.
SELECT *
FROM table
WHERE birtdate BETWEEN x AND Y
ORDER BY logintime DESC
If I defined an index on just birtdate, mysql would use filesort to order the results which I would like to avoid (table is getting big, query is popular).
Defining an index (logintime, birthdate) doesn't make sense to me since logintime isn't even in the WHERE clause (I'm only restricting the result set by birthdate)
Any elegant solutions in mysql?