systemadmin.es » DBA » Ampliar el espacio disponible para tablas MEMORY

Ampliar el espacio disponible para tablas MEMORY

En algunos casos es útil mantener ciertos datos volátiles en una tabla en memoria, por ejemplo simulando una vista materializada para acceder a cierto subconjunto de datos. Vamos a ver como modificar el límite de memoria por cada tabla.

La variable que controla el límite de memoria que puede consumir una tabla MEMORY es el max_heap_table_size que podemos ver mediante un show variables:

mysql> show variables like 'max_heap_table_size';
+---------------------+------------+
| Variable_name       | Value      |
+---------------------+------------+
| max_heap_table_size | 1073741824 |
+---------------------+------------+
1 row in set (0.00 sec)

En la documentación de MySQL sobre la variable max_heap_table_size podemos encontrar que tiene un límite tanto por arriba como por abajo: 16384-4294967295. Podemos combrobarlo con:

mysql> set session max_heap_table_size=1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> create table ejemplo(id int) ENGINE=MEMORY;
Query OK, 0 rows affected (0.02 sec)

Ahora si vemos el Max_data_length del table status podemos ver el mínimo del max_heap_table_size (16384):

mysql> show table status like 'ejemplo'\G
*************************** 1. row ***************************
           Name: ejemplo
         Engine: MEMORY
        Version: 10
     Row_format: Fixed
           Rows: 0
 Avg_row_length: 8
    Data_length: 0
Max_data_length: 16384
   Index_length: 0
      Data_free: 0
 Auto_increment: NULL
    Create_time: NULL
    Update_time: NULL
     Check_time: NULL
      Collation: latin1_swedish_ci
       Checksum: NULL
 Create_options:
        Comment:
1 row in set (0.00 sec)

Para establecer límites a las tablas MEMORY independientes del límite del sistema podemos hacerlo estableciendo el max_heap_table_size en la sesión mediante SET SESSION:

mysql> set session max_heap_table_size=1024*1024*10;
Query OK, 0 rows affected (0.00 sec)

mysql> create table ejemplo1(id int) ENGINE=MEMORY;
Query OK, 0 rows affected (0.05 sec)

A continuación podemos volver a modificar el valor para la segunda tabla:

mysql> set session max_heap_table_size=1024*1024*20;
Query OK, 0 rows affected (0.00 sec)

mysql> create table ejemplo2(id int) ENGINE=MEMORY;
Query OK, 0 rows affected (0.01 sec)

Mediante el show table status podremos ver como los Max_data_length són diferentes:

mysql> show table status like 'ejemplo%'\G
*************************** 1. row ***************************
           Name: ejemplo1
         Engine: MEMORY
        Version: 10
     Row_format: Fixed
           Rows: 0
 Avg_row_length: 8
    Data_length: 0
Max_data_length: 10485760
   Index_length: 0
      Data_free: 0
 Auto_increment: NULL
    Create_time: NULL
    Update_time: NULL
     Check_time: NULL
      Collation: latin1_swedish_ci
       Checksum: NULL
 Create_options:
        Comment:
*************************** 2. row ***************************
           Name: ejemplo2
         Engine: MEMORY
        Version: 10
     Row_format: Fixed
           Rows: 0
 Avg_row_length: 8
    Data_length: 0
Max_data_length: 20971520
   Index_length: 0
      Data_free: 0
 Auto_increment: NULL
    Create_time: NULL
    Update_time: NULL
     Check_time: NULL
      Collation: latin1_swedish_ci
       Checksum: NULL
 Create_options:
        Comment:
2 rows in set (0.00 sec)

Relacionados

Imprimir Imprimir

Deja un comentario:

XHTML - Tags permitidos:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>