Managing Memory Use
The server needs sufficient memory to maintain all MEMORY tables that are in use at the same time.
Memory is not reclaimed if you delete individual rows from a MEMORY table. Memory is reclaimed only
when the entire table is deleted. Memory that was previously used for deleted rows is re-used for
new rows within the same table. To free all the memory used by a MEMORY table when you no longer
require its contents, execute DELETE or TRUNCATE TABLE to remove all rows, or remove the table
altogether using DROP TABLE. To free up the memory used by deleted rows, use ALTER TABLE
ENGINE=MEMORY to force a table rebuild.
The memory needed for one row in a MEMORY table is calculated using the following expression:
SUM_OVER_ALL_BTREE_KEYS(max_length_of_key + sizeof(char*) * 4)
+ SUM_OVER_ALL_HASH_KEYS(sizeof(char*) * 2)
+ ALIGN(length_of_row+1, sizeof(char*))
ALIGN() represents a round-up factor to cause the row length to be an exact multiple of the char
pointer size. sizeof(char*) is 4 on 32-bit machines and 8 on 64-bit machines.
As mentioned earlier, the max_heap_table_size [519] system variable sets the limit on
the maximum size of MEMORY tables. To control the maximum size for individual tables,
set the session value of this variable before creating each table. (Do not change the global
max_heap_table_size [519] value unless you intend the value to be used for MEMORY tables
created by all clients.) The following example creates two MEMORY tables, with a maximum size of 1MB
and 2MB, respectively:
... zobacz całą notatkę
Komentarze użytkowników (0)