phpguru — 2011-03-19T14:04:35-04:00 — #1
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?
and one more question, should i use DISTINCT or GROUP BY to filter duplicate records?
r937 — 2011-03-19T16:19:34-04:00 — #2
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
oddz — 2011-03-19T20:21:26-04:00 — #3
Assuming uid is the primary key and uname is unique you should not have duplicates.
phpguru — 2011-03-20T02:03:59-04:00 — #4
i mean, DISTINCT and GROUP BY, which take more a lot of resources?
r937 — 2011-03-20T04:24:19-04:00 — #5
it's not a question of resources, it's a question of why do you allow duplicates to occur in the first place?