Bug #4579 Execution of SP crashes server
Submitted: 16 Jul 2004 19:25 Modified: 22 Jul 2004 17:01
Reporter: Alexey Stroganov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.1-bk OS:Linux (Linux)
Assigned to: Per-Erik Martin CPU Architecture:Any

[16 Jul 2004 19:25] Alexey Stroganov
Description:
Stored procedure from OSDL-DBT2 crashes mysql server. I've simplified it and put it 
below:  
 
drop table if exists t_bug_1; 
drop procedure if exists bug_1; 
drop procedure if exists bug_2; 
 
create table t_bug_1 (f1 int, f2 int); 
insert into t_bug_1 values (1,1); 
 
delimiter |; 
 
CREATE PROCEDURE bug_sp () 
BEGIN 
  DECLARE sf1 INT; 
  select f1 INTO sf1 from t_bug_1 where f1=1 and f2=1; 
  update t_bug_1 set f2 = f2 + 1 where f1=1 and f2=1; 
  call bug_sp2(); 
END| 
 
CREATE PROCEDURE bug_sp2 () 
BEGIN 
  DECLARE t2 INT; 
END| 
delimiter ;| 
 
 

How to repeat:
put stored procedure to file and then just load it:  
 
mysql test  < bug_sp.sql 
 
after that try to call SP several times: 
 
./mysql test 
 
mysql> call bug_sp(); 
mysql> call bug_sp(); 
... 
 

Suggested fix:
[22 Jul 2004 14:51] Alexey Stroganov
I've simplified new test case that crashes server with the same symptoms: 
 
drop procedure if exists bug_sp_2; 
drop table if exists bug_sp_2; 
 
create table bug_sp_2 (f1 int, f2 int, f3 int); 
insert into  bug_sp_2 values (1,1,1); 
 
delimiter |; 
CREATE PROCEDURE bug_sp_2() 
BEGIN 
 
   DECLARE      tmp_o_id INT; 
   DECLARE      tmp_d_id INT default 1; 
 
   while tmp_d_id <= 2 DO 
   BEGIN 
 
#Query below crashes server 
     SELECT f1 INTO tmp_o_id FROM bug_sp_2 WHERE f2=1 AND f3=1; 
 
#Query below not 
#    SELECT f1 INTO tmp_o_id FROM bug_sp_2 WHERE f2=1; 
 
     SET tmp_d_id = tmp_d_id + 1; 
 
   END; 
   END WHILE; 
 
END| 
delimiter ;|
[22 Jul 2004 14:53] Alexey Stroganov
I've simplified new test case that crashes server with the same symptoms: 
 
drop procedure if exists bug_sp_2; 
drop table if exists bug_sp_2; 
 
create table bug_sp_2 (f1 int, f2 int, f3 int); 
insert into  bug_sp_2 values (1,1,1); 
 
delimiter |; 
CREATE PROCEDURE bug_sp_2() 
BEGIN 
 
   DECLARE      tmp_o_id INT; 
   DECLARE      tmp_d_id INT default 1; 
 
   while tmp_d_id <= 2 DO 
   BEGIN 
 
#Query below crashes server 
     SELECT f1 INTO tmp_o_id FROM bug_sp_2 WHERE f2=1 AND f3=1; 
 
#Query below not 
#    SELECT f1 INTO tmp_o_id FROM bug_sp_2 WHERE f2=1; 
 
     SET tmp_d_id = tmp_d_id + 1; 
 
   END; 
   END WHILE; 
 
END| 
delimiter ;|
[22 Jul 2004 17:01] Per-Erik Martin
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html