Tuning join_buffer_size variable

Basic Details

The join_buffer_size variable sets the buffer size for join queries that require a full table scan because they cannot use an index.

Releem automatically tunes join_buffer_size and 44 other variables to improve MySQL performance. Try Releem for Free, or deepen your understanding by reading our detailed article.

join_buffer_size – Usage

The join_buffer_size variable can be adjusted to set the buffer cache size when adding in indexes doesn't work. Indexes are used to improve query times by helping MySQL find rows with specific column values more quickly. A full table scan, starting with the first row, is used without indexes.

The join buffer is allocated when the server needs a full table join with no indexes. After the query is complete, the memory allocation is freed. In 64-bit platforms, Windows shortens join_buffer_size values above 4GB to 4GB with a warning.

join_buffer_size – Configuration

The join_buffer_size variable can be configured dynamically or globally, using the following configuration methods:

Configuration File:
join_buffer_size = XX

Replace XX with a value to suit your database needs. Must restart MySQL servers to see changes applied.

Command Line:
mysqld> set global join_buffer_size = XX

Replace XX with a value to suit your database needs. This change will only be applied to new connections. Make a new connection to the server and the values will update.

SET GLOBAL will not persist through a server restart.

join_buffer_size Considerations

Join_buffer_size default is 256KB, while the maximum is 4GB.

Because join_buffer_size is allocated per connection, MySQL is allocating the set buffer size value, times the number of max connections, at startup. The default join_buffer_size rarely needs to be increased, as it wastes server memory without helping performance.

You may induce significant performance degradation if the join_buffer cache size is larger than the queries that need it. Instead of trying to increase join_buffer_size to improve performance, consider adding indexes for your joins. MySQL can log queries that don't contain indexes for easy identification. Then these queries can have indexes added or modified as necessary.

A common recommendation for join_buffer_size is 1% of available RAM. If adding indexes is not possible, instead of changing the value of join_buffer_size globally, change it for a session when you anticipate when large join queries. You can also change the value of join_buffer_size on a per-query basis if it's only needed for a handful of queries.

With Releem, you don't have to worry about any of the nuances of join_buffer_size or other variables. Releem will assess your server and provide a MySQL Performance Score and make configuration recommendations. Releem can automatically apply the recommended settings to improve MySQL Performance Score. And the whole time you don't have to do anything.
Releem automatically detects MySQL performance degradation and optimizes MySQL configuration files