The sort buffer, which is controlled by the
sort_buffer_size setting, is probably one of the
most-discussed MySQL settings. Interestingly, in many cases it
has a lot less potential to help performance than to hurt it, so
configuring it is often about avoiding trouble rather than
gaining a lot of performance.
The variable controls the size of a buffer that’s created whenever MySQL has to sort rows. It is per-query, meaning each query gets its own buffer, and it’s allocated to its full size, not as-much-as-needed. This makes large settings potentially dangerous.
The worst abuse of this variable we’ve seen came from a server that was tuned with a script. The script relied on a naive formula that looked at a simplistic ratio of some server variables. Due to the server’s workload the script was never satisfied and continually suggested increasing this variable, which eventually was set to 1GB. The effect was that …
[Read more]