Re:Digg: 40x Performance Increase by Sorting in PHP Rather t...
by rythie on Wednesday March 24, 2010 @07:35AM
(#1215446)
You can only do it on the index, the query from the index will return in the sort order. You have to be very careful in your index and query design to make this work.
For example if your index is (username, date_posted) then you can do something like
SELECT * FROM table WHERE username='user' ORDER BY date_posted
but if you do
SELECT * FROM table WHERE username IN ('user','user2') ORDER BY date_posted
then it will need a temporary table.
You could change your index to (date_posted, username) to make it work, but then it will be slow when querying a small percent of the users.
For example if your index is (username, date_posted) then you can do something like
but if you do then it will need a temporary table.You could change your index to (date_posted, username) to make it work, but then it will be slow when querying a small percent of the users.