How MySQL Uses Memory
How MySQL Uses Memory ,
->A stack (variable thread_stack)
->A connection buffer (variable net_buffer_length)
->A result buffer (variable net_buffer_length)
->The connection buffer and result buffer each begin with a size equal to net_buffer_length bytes, but are dynamically enlarged up to max_allowed_packet bytes as needed. The result buffer shrinks to net_buffer_length bytes after each SQL statement. While a statement is running, a copy of the current statement string is also allocated.
->All threads share the same base memory.
->When a thread is no longer needed, the memory allocated to it is released and returned to the system unless the thread goes back into the thread cache. In that case, the memory remains allocated.
->Only compressed MyISAM tables are memory mapped. This is because the 32-bit memory space of 4GB is not large enough for most big tables. When systems with a 64-bit address space become more common, we may add general support for memory mapping.
->Each request that performs a sequential scan of a table allocates a read buffer (variable read_buffer_size).
->When reading rows in an arbitrary sequence (for example, following a sort), a random-read buffer (variable read_rnd_buffer_size) may be allocated to avoid disk seeks.