Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is a one-line MySQL stored function overflowing the stack?

Tags:

mysql

I'm just learning the stored-function and -procedure syntax for MySQL. I hard-coded a function that just returns the number 12, and it overflows the stack. Anybody know what's up here? This is MySQL 5.5.30.

mysql> DELIMITER //
mysql> CREATE FUNCTION `newItemID`()
    -> RETURNS BIGINT
    -> SQL SECURITY INVOKER
    -> BEGIN
    ->   RETURN 12;
    -> END;
    -> //
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;
mysql> SELECT newItemID();
ERROR 1436 (HY000): Thread stack overrun:  12288 bytes used of a 131072 byte stack, and 128000 bytes needed.  Use 'mysqld --thread_stack=#' to specify a bigger stack.
like image 321
Oscar Avatar asked Jan 24 '14 23:01

Oscar


1 Answers

like @wrikken pointed out this is a known bug when you're running a 128k thread stack, however it was fixed in newer versions of mysql and it was supposed to be fixed, so maybe you're running an older version or a non-official package.

It is reccommended to use a stack that has at least 192k on it, so you could go to your my-small.cnf and make my-innodb-heavy-4G.cnf:thread_stack = 192k my-small.cnf:thread_stack = 128K.

All of these remedies are available in the mysql bug report, but please test this offline before modifying your server. Make sure the offline localhost has the same settings and configurations just like your live server, that is if you're using a live server. Basically make an exact duplicate of your server and test it offline and if the fix works and doesn't cause any issues, put it online.

like image 107
user3148596 Avatar answered Sep 30 '22 20:09

user3148596