Forum Moderators: coopster
Now, I know if you're returning only 100's or even 1000's of rows then a simple ORDER BY clause will work fine (better than developing a sorting algorithm in PHP).
However, I can't seem to see where PHP would be better at sorting than MySQL. Does anyone have any experience with PHP being a better choice to sort something than MySQL?
--Nick
for some things I use php to chunk through the data and sort/split/chunk but I would say most of the time mysql is better
the problem with people saying that to you is they need to qualify what they mean
for a standard website, things that would come into play
dedicated or shared server
what are the specs on the server
how much avg daily traffic does the site get
how much traffic does the page get
what type of data are you trying to sort
how much data are you trying to sort
what are the sort criteria
are you using the same number of queries in your comparison
and I could probably think of a ton more criteria that would cause blanket statements to fall on their face ;)
my approach is: best tool for the job, always
I would always sort in mysql first, if I could identify an issue with that sort, then I would look at alternatives
though I guess to answer the question exactly
>> When would it be absolutely necessary to sort a record set in MySQL?
never
nothing is absolutely necessary, but some things are more foolish than others ;)
The load on the server, or the differential performance of the mySQL server vs the PHP server when they are on different CPUs is probably important, I would perform the sort where it returns the fastest, if that's what I was looking for -- on the other hand, I also wouldn't want a large return set from a databse that requires sorting to degrade the performance of my PHP host which is doing other things besides fronting a mySQL database.
You have options, testing always gives you answers.
The database design and your control over it may dictate what method you should use for any particular query.