Bug #13133 Local variables in stored procedures are not initialized correctly.
Submitted: 13 Sep 2005 9:42 Modified: 14 Sep 2005 0:19
Reporter: Per-Erik Martin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S2 (Serious)
Version:5.0.12 OS:Any (Any)
Assigned to: Bugs System CPU Architecture:Any

[13 Sep 2005 9:42] Per-Erik Martin
Description:
Local variables are initialized to null, but incorrectly so. Local changes in one
begin-end block overrides the value in a parallel block.

The example gives the result

mysql> call bug()//
+------+
| a    |
+------+
| NULL |
+------+
1 row in set (0.00 sec)

+---+
| a |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

+---+
| b |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

where the expected value of 'b' is NULL.

How to repeat:
delimiter //
create procedure bug()
begin
  begin
    declare a int;

    select a;
    set a = 1;
    select a;
  end;
  begin
    declare b int;
    select b;
  end;
end//
delimiter ;

call bug();
[13 Sep 2005 11:23] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/29730
[14 Sep 2005 0:19] Paul DuBois
Noted in 5.0.13 changelog.