sql >> Base de Datos >  >> RDS >> Mysql

¿Por qué este activador de MySQL provoca un desbordamiento de pila?

Me encontré con el mismo problema hoy, cada activador provocaba un desbordamiento de la pila. Resultó que mi instalación de Zend Community Server viene con un archivo my.cnf predeterminado en el que el tamaño de thread_stack se estableció en 128K, lo que resultó en 131072 bytes disponibles para la pila en cada hilo:

mysql> show variables where `Variable_name` = 'thread_stack';
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| thread_stack  | 131072 |
+---------------+--------+

Así que comenté la línea en /usr/local/zend/mysql/data/my.cnf, reinicié el demonio mysql y ¡listo! El predeterminado 192K es

mysql> show variables where `Variable_name` = 'thread_stack';
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| thread_stack  | 196608 |
+---------------+--------+

Ahora el gatillo de tu mesa y tchester funcionan perfectamente :) (sin embargo, ten en cuenta el delimitador)

mysql> CREATE TABLE `job_title` (
    ->   `job_id` int(11) NOT NULL AUTO_INCREMENT,
    ->   `position_id` int(11) DEFAULT NULL,
    ->   `title` varchar(255) COLLATE latin1_general_cs NOT NULL,
    ->   `selectable` tinyint(4) NOT NULL DEFAULT '0',
    ->   PRIMARY KEY (`job_id`),
    ->   UNIQUE KEY `title` (`title`)
    -> ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.14 sec)

mysql> DELIMITER &&
mysql> create trigger job_position_trigger   
    ->   before insert on job_title for each row  
    -> begin    
    ->     if new.position_id is null then       
    ->        set @position = (select max(position_id)+1 from job_title);
    ->        if @position is null then set @position = 1; end if;
    ->        set new.position_id = @position;    
    ->     end if;  
    -> end; 
    -> &&
Query OK, 0 rows affected (0.29 sec)

mysql> DELIMITER ;
mysql> insert into job_title (title, selectable) values ("test", 1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into job_title (title, selectable) values ("test2", 3);
Query OK, 1 row affected (0.00 sec)

mysql> select * from job_title;
+--------+-------------+-------+------------+
| job_id | position_id | title | selectable |
+--------+-------------+-------+------------+
|      1 |           1 | test  |          1 |
|      2 |           2 | test2 |          3 |
+--------+-------------+-------+------------+
2 rows in set (0.00 sec)

El error que recibió, 9024 bytes usados ​​de una pila de 131072 bytes y 128000 bytes necesarios, tiene sentido:9024 + 128000> 131072.