Bug #9441 UPDATE statement within stored procedure crashes server
Submitted: 29 Mar 2005 5:30 Modified: 29 Mar 2005 14:12
Reporter: Steffen Reinecke Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.2-alpha/5.0.3 dev OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[29 Mar 2005 5:30] Steffen Reinecke
Description:
The mysql server crashes while updating a table row within a stored procedure called multiple times. Don't know why ...

see How to repeat section

...

it also crashes when i add the user_id as parameter to the procedure and call:
do_opt_in(161); /* works fine */
do_opt_in(162); /* crashes */

I have tested it on 2 different Linux machines and also with the mysql 5 developer branch (5.0.3-beta dev) from today.

The Trace ...:
Version: '5.0.2-alpha-standard'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Official MySQL-standard binary
pure virtual method called
mysqld got signal 6;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=16777216
read_buffer_size=131072
max_used_connections=2
max_connections=100
threads_connected=2
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 80383 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd=0x8a90e08
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
Cannot determine thread, fp=0xbfe5def8, backtrace may not be correct.
Stack range sanity check OK, backtrace follows:
0x808edf3
0x8301538
0x830cc11
0x83018c9
0x830d030
0x8371d38
0x8371d5d
0x837173b
0x804f901
0x805d861
0x805da5b
0x8056b52
0x8061a3c
0x80c069c
0x80e58fd
0x80e4945
0x80a05f7
0x8157550
0x8157457
0x81556d4
0x8155d6f
0x80a2753
0x80a3eb9
0x809d798
0x809d143
0x809c85a
0x82fecec
0x83287ca
New value of fp=(nil) failed sanity check, terminating stack trace!
Please read http://dev.mysql.com/doc/mysql/en/Using_stack_trace.html and follow instructions on how to resolve the stack trace. Resolved
stack trace is much more helpful in diagnosing the problem, so please do
resolve it
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x89be448 = UPDATE `user` SET `user_person_id` = 32, `status_id`=1 WHERE `id`= 161 AND `opt_in_key`='88c8d3f0d0ff0c3feeda0fc10d45db68'
thd->thread_id=6

How to repeat:

CREATE DATABASE `testcase6` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `testcase6`;

CREATE TABLE `user` (
  `id` bigint(128) NOT NULL auto_increment,
  `login` varchar(32) NOT NULL default '',
  `user_person_id` bigint(128) default NULL,
  `opt_in_key` varchar(32) default NULL,
  `status_id` int(1) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `login` (`login`),
  KEY `user_person_id` (`user_person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

delimiter //
CREATE PROCEDURE do_opt_in ()
SQL SECURITY DEFINER
BEGIN
        UPDATE `user` SET `user_person_id` = 32, `status_id`=1 WHERE `id`= 161 AND `opt_in_key`='88c8d3f0d0ff0c3feeda0fc10d45db68';
END
//
delimiter ;

INSERT INTO `user` ( `id` , `login` , `user_person_id` , `opt_in_key` , `status_id` ) VALUES ('161', 'test', NULL , '88c8d3f0d0ff0c3feeda0fc10d45db68', '0');

CALL do_opt_in();
CALL do_opt_in();

# The Result from command line
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14 to server version: 5.0.2-alpha-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
mysql> CREATE DATABASE `testcase6` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0,00 sec)

mysql> USE `testcase6`;
Database changed
mysql>
mysql> CREATE TABLE `user` (
    ->   `id` bigint(128) NOT NULL auto_increment,
    ->   `login` varchar(32) NOT NULL default '',
    ->   `user_person_id` bigint(128) default NULL,
    ->   `opt_in_key` varchar(32) default NULL,
    ->   `status_id` int(1) NOT NULL,
    ->   PRIMARY KEY  (`id`),
    ->   UNIQUE KEY `login` (`login`),
    ->   KEY `user_person_id` (`user_person_id`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Query OK, 0 rows affected (0,13 sec)

mysql>
mysql>
mysql> delimiter //
mysql> CREATE PROCEDURE do_opt_in ()
    -> SQL SECURITY DEFINER
    -> BEGIN
    ->         UPDATE `user` SET `user_person_id` = 32, `status_id`=1 WHERE `id`= 161 AND `opt_in_key`='88c8d3f0d0ff0c3feeda0fc10d45db68';
    -> END
    -> //
Query OK, 0 rows affected (0,00 sec)

mysql> delimiter ;
mysql>
mysql> INSERT INTO `user` ( `id` , `login` , `user_person_id` , `opt_in_key` , `status_id` ) VALUES ('161', 'test', NULL , '88c8d3f0d0ff0c3feeda0fc10d45db68', '0');
Query OK, 1 row affected (0,01 sec)

mysql>
mysql> CALL do_opt_in();
Query OK, 1 row affected (0,00 sec)

mysql> CALL do_opt_in();
ERROR 2013 (HY000): Lost connection to MySQL server during query

Suggested fix:
sorry ... i don't know a fix
[29 Mar 2005 7:34] Heikki Tuuri
Steffen,

please resolve the stack trace.

Does the bug report contain the complete instructions on how to reproduce the bug?

Regards,

Heikki
[29 Mar 2005 14:12] MySQL Verification Team
Hi,

Thank you for the report!
I was able reproduce it with 5.0.2, but it works fine for me with latest 5.0 BK tree
[29 Mar 2005 23:32] Steffen Reinecke
Sorry, yes you are right. It was not the same problem with the bk 5.0 tree. The reasen for the crashes there, was a corrupt inno db file or old prvilege tables. Couldn't figure it out. A mysql_install_db from the bk 5.0 source to a new directory fixed the problem.