Bug #63664 User defined function causes a disconnect to the mysql server
Submitted: 8 Dec 2011 4:43 Modified: 9 Dec 2011 5:37
Reporter: Jason Romanik Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S3 (Non-critical)
Version:5.5.16 OS:Windows (7)
Assigned to: CPU Architecture:Any

[8 Dec 2011 4:43] Jason Romanik
Description:
Using Sqlyog, I nested a user defined function and select statement inside a user defined function.  All three were created from the same view. When I try to invoke the function it returned the following statement:

error code : 2003
can't connect to mysql server on 'localhost' (10061)

After that I couldn't reconnect to mysql.  I have to restart my computer to get a connection back. 
Here's the function:

DELIMITER $$

USE `retrosheet`$$

DROP FUNCTION IF EXISTS `erp600test`$$

CREATE DEFINER=`root`@`localhost` FUNCTION `erp600test`( b VARCHAR(8) , g INT(8)  ) RETURNS DECIMAL(7,4)
BEGIN
    DECLARE m INT;
    DECLARE erp600 DECIMAL (7,4);
SELECT erp600count(b,g) INTO m;
    
SET erp600 = 
(SELECT SUM(erp) 
FROM 
(
SELECT erp 
FROM 2010_event_stats
WHERE ((bat_id=b AND bat_event_fl=1) OR (base1_run_id=b AND event_cd IN (4,6,8)) OR (base2_run_id=b AND event_cd IN (4,6,8))OR (base3_run_id=b AND event_cd IN (4,6,8))) AND game_dt<g
ORDER BY game_dt
LIMIT 0,m
)
AS temp);
   RETURN (erp600);
    END$$

DELIMITER ;

To invoke the function I used:

SELECT erp600test ("jeted001", 20101005);

I expect a decimal to be returned.

How to repeat:
Create  view_1 form  table_1.
Create function_1 from view_1.
Nest function_1 and (SELECT statement FROM view_1) into function_2.
Invoke function_2 (parameter)
[8 Dec 2011 7:08] Valeriy Kravchuk
Please, check if the same problem still happens with a newer version, 5.5.18. 

If it does, please, send complete test case, with all table(s) and view(s) needed. In your code there is a reference to erp600count() function that is not defined, etc
[9 Dec 2011 5:14] Valeriy Kravchuk
Not repeatable with 5.5.19.
[9 Dec 2011 5:37] Jason Romanik
What does not repeatable mean?