What's field should be INDEX in mysql?

today, i checked my slow query log and saw lots of slow queries.

it’s looks like:

SELECT uid,uname FROM usertbl WHERE country=‘us’ ORDER BY lastlogin DESC LIMIT 0,20;

i INDEXED country field.
so should i index lastlogin field? :frowning:

and one more question, should i use DISTINCT or GROUP BY to filter duplicate records?

try it and see what happens

in general, yes

but ~not~ in this case!

if you are getting duplicates from the query that you posted, then you have some pretty serious issues

Assuming uid is the primary key and uname is unique you should not have duplicates.

i mean, DISTINCT and GROUP BY, which take more a lot of resources?

it’s not a question of resources, it’s a question of why do you allow duplicates to occur in the first place?