[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Shared access to the key cache improves performance but does not eliminate contention among threads entirely. They still compete for control structures that manage access to the key cache buffers. To reduce key cache access contention further, MySQL 4.1.1 offers the feature of multiple key caches. This allows you to assign different table indexes to different key caches.
When there may be multiple key caches, the server must know which cache to
use when processing queries for a given MyISAM
table. By default, all
MyISAM
table indexes are cached in the default key cache. To assign
table indexes to a specific key cache, use the CACHE INDEX
statement.
For example, The following statement assigns indexes from the tables
t1
, t2
, and t3
to the key cache named hot_cache
:
mysql> CACHE INDEX t1, t2, t3 IN hot_cache; +---------+--------------------+----------+----------+ | Table | Op | Msg_type | Msg_text | +---------+--------------------+----------+----------+ | test.t1 | assign_to_keycache | status | OK | | test.t2 | assign_to_keycache | status | OK | | test.t3 | assign_to_keycache | status | OK | +---------+--------------------+----------+----------+ |
Note: If the server has been built with the ISAM
storage
engine enabled, ISAM
tables use the key cache mechanism. However,
ISAM
indexes use only the default key cache and cannot be reassigned to
a different cache.
The key cache referred to in a CACHE INDEX
statement can be created
by setting its size with a parameter setting statement or in the server
parameter settings. For example:
mysql> SET GLOBAL keycache1.key_buffer_size=128*1024; |
To destroy a key cache, set its size to zero:
mysql> SET GLOBAL keycache1.key_buffer_size=0; |
See 10.4.2 Structured System Variables for a description of the syntax used for referring to structured key cache system variables.
By default, table indexes are assigned to the main (default) key cache created at the server start-up. When a key cache is destroyed, all indexes assigned to it become assigned to the default key cache again.
For a busy server, we recommend a strategy that uses three key caches:
One reason the use of three key caches be beneficial is that access to one key cache structure does not block access to the others. Queries that access tables assigned to one cache do not compete with queries that access tables assigned to another cache. Performance gains occur for other reasons as well:
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |