Is it faster for the randomize the sort order of a large set of results on the MySQL server or after I have received the data in PHP?

Does anyone have any data to backup either side, or even anecdotal experience?

Comments

I would test to demonstrate whether a problem exists either way, before worrying about it. You'd have to have a huge, huge amount of data before it would matter much, I expect. In fact, it would be interesting to compare the amount of time you've taken posting this and digesting the answers, compared to choosing one approach, implementing it, switching, and comparing. (Just speculation, not a criticism; we all do these mental exercises.)

Written by le dorfier

yes, but if someone answers this question well, then I will learn without all this investment of time, and i and others can improve their code. I think it's a good question to ask regardless of whether a problem currently exists.

Written by nickf

Accepted Answer

My educated guess is that MySQL wins hands down. It's made to handle data this way. The sheer overhead of having to move all the data over to PHP for sorting gives it an advantange to boot.

You can find out for yourself by doing some benchmarking, of course.

Written by Paolo Bergantino
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki