join_buffer_size
Buffer for joins that cannot use an index, including hash joins.
- 預設
256KB- Range
- 128 bytes to about 2^64 bytes
- Restart needed
- 否
- Default checked on
- MySQL 8.4 LTS
其作用
Used by hash joins (which replaced block nested-loop joins in MySQL 8.0.20) and by Batched Key Access. One buffer can be allocated per such join in a query.
預設值
256KB. 262144 bytes (MySQL 8.4).
Check the current value
SHOW GLOBAL VARIABLES LIKE 'join_buffer_size'; SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME FROM performance_schema.variables_info WHERE VARIABLE_NAME = 'join_buffer_size';
Change it
SET SESSION join_buffer_size = 4194304; -- this connection SET GLOBAL join_buffer_size = 4194304; -- new connections, until restart SET PERSIST join_buffer_size = 4194304; -- new connections, and after restarts
No restart. SET GLOBAL (or SET PERSIST, which also survives restarts) applies to connections opened afterwards; existing connections keep their session value unless they SET it themselves.
When to change it
Raise per session for analytic queries doing large hash joins; first look for a missing index.
What can go wrong
Allocated per join per connection; large global values add up quickly.
Questions about join_buffer_size
What is the default value of join_buffer_size in MySQL?
256KB. 262144 bytes (MySQL 8.4).
Does changing join_buffer_size require a restart?
No. No restart. SET GLOBAL (or SET PERSIST, which also survives restarts) applies to connections opened afterwards; existing connections keep their session value unless they SET it themselves.
When should I change join_buffer_size?
Raise per session for analytic queries doing large hash joins; first look for a missing index.
Back to all MySQL settings, or check the MySQL manual for every option.
Check join_buffer_size on your own server
SQLly runs the query above against MySQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.