There have been a few posts by Sheeri and Baron today on the MySQL sort_buffer_size variable. I wanted to add some more information about this buffer, what is impacted when it is changed, and what to do about it?
The first thing you need to know is the sort_buffer_size is a per session buffer. That is this memory is assigned per connection/thread. I’ve seen clients that set this assuming it’s a global buffer Don’t Assume – Per Session Buffers.
Second, internally in the OS usage independently of MySQL, there
is a threshold > 256K. From Monty Taylor “if buffer is set
to over 256K, it uses mmap() instead of
malloc() for memory allocation. Actually – this is a
libc malloc thing and is tunable, but …