Bug #42779 ERROR 2013 (HY000): Lost connection to MySQL server during query
Submitted: 12 Feb 2009 6:06 Modified: 12 Mar 2009 7:13
Reporter: rajesh goswami Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S1 (Critical)
Version:5.0.27-log OS:Linux
Assigned to: CPU Architecture:Any
Tags: Critical Issue

[12 Feb 2009 6:06] rajesh goswami
Description:
I have created a Function in Mysql. But When I m going to execute. Is shows the error like  mysql> select getSeq();
ERROR 2013 (HY000): Lost connection to MySQL server during query
Function Code:
mysql> delimiter   $$;
mysql> CREATE FUNCTION `getSeq`() RETURNS int(11)
    -> DETERMINISTIC
    -> READS SQL DATA
    -> BEGIN
    -> DECLARE id int;
    -> insert into get_seq (seq) values (0);
    -> SET id = LAST_INSERT_ID();
    -> DELETE from get_seq where seq = id;
    -> RETURN id;
    -> END
    -> $$;
Query OK, 0 rows affected (0.00 sec)

If anybody have Idea to resolve this problem.. Please let me know Immediatly...

How to repeat:
Create UDF on Mysql 5.0.27-log and try to execute
[12 Feb 2009 6:09] MySQL Verification Team
5.0.27 is too old.  please try 5.0.67 or 5.1.31 and if server crashes again, then show us the mysql error log.  thanks.
[12 Feb 2009 7:05] rajesh goswami
Thanks for the prompt reply. But I am facing this problem on My Production server, So Mysql version can not upgrade easily. If the solution is available in Existing versin then Please give me immediatly... Thanks
[12 Feb 2009 7:13] MySQL Verification Team
Hi!  it works on 5.0.67:

mysql>
mysql> delimiter   $$
mysql> CREATE FUNCTION `getSeq`() RETURNS int(11)
    -> DETERMINISTIC
    -> READS SQL DATA
    -> BEGIN
    -> DECLARE id int;
    -> insert into t1 (seq) values (0);
    -> SET id = LAST_INSERT_ID();
    -> DELETE from t1 where seq = id;
    -> RETURN id;
    -> END
    -> $$
Query OK, 0 rows affected (0.03 sec)

mysql>
mysql> delimiter ;
mysql> select getSeq();
+----------+
| getSeq() |
+----------+
|        1 |
+----------+
1 row in set (0.03 sec)

mysql> select getSeq();
+----------+
| getSeq() |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)

mysql> select version();
+---------------------+
| version()           |
+---------------------+
| 5.0.67-community-nt |
+---------------------+
1 row in set (0.00 sec)

Try repairing all tables in the `mysql` database, in case one of them is corrupt.  Otherwise, upgrade is needed.
[13 Mar 2009 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".