Bug #1654 Stored Procedure Crash if contains subquery and set function
Submitted: 24 Oct 2003 19:52 Modified: 4 Dec 2003 6:27
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0 OS:Linux (SuSE 8.2)
Assigned to: Per-Erik Martin CPU Architecture:Any

[24 Oct 2003 19:52] Peter Gulutzan
Description:
A stored procedure (actually a function) crashes if it contains a subquery which in turn 
contains a set function, MAX -- inside the RETURN. 
 
The subquery contains a SELECT, which is normally illegal in a function. 

How to repeat:
mysql> create table table_1 (date_column date, smallint_column smallint); 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> insert into table_1 values ('2001-04-25',17); 
Query OK, 1 row affected (0.00 sec) 
 
mysql> create function max_ () returns date return (select max(date_column) from table_1 
where smallint_column > 5); 
Query OK, 0 rows affected (0.01 sec) 
 
mysql> select max_(); 
ERROR 2013 (HY000): Lost connection to MySQL server during query
[27 Oct 2003 3:11] Indrek Siitan
Stack trace:

#0  st_select_lex_node::include_down (this=0xaa30308, upper=0xaa2d0d4)
    at sql_lex.cc:1045
#1  0x80a542e in mysql_new_select (lex=0xaa2d000, move_down=true)
    at sql_parse.cc:3866
#2  0x80b9adc in yyparse (yythd=0xa980018) at sql_yacc.yy:6423
#3  0x8158225 in db_find_routine (thd=0xa980018, type=1, 
    name=0xaa0a060 "max_", namelen=4, sphp=0xaa04bb8) at sp.cc:145
#4  0x81590f8 in sp_cache_functions (thd=0xa980018, lex=0xa980290) at sp.cc:424
#5  0x80a0289 in mysql_execute_command (thd=0xa980018) at sql_parse.cc:1667
#6  0x80a5895 in mysql_parse (thd=0xa980018, inBuf=0xaa0a028 "select max_()", 
    length=13) at sql_parse.cc:3977
#7  0x809f4f7 in dispatch_command (command=COM_QUERY, thd=0xa980018, 
    packet=0xa9d0019 "select max_()", packet_length=14) at sql_parse.cc:1310
#8  0x809eefa in do_command (thd=0xa980018) at sql_parse.cc:1144
#9  0x809e593 in handle_one_connection (arg=0xa980018) at sql_parse.cc:911
#10 0x2853541f in _thread_start () from /usr/lib/libc_r.so.4
#11 0x0 in ?? ()
[4 Dec 2003 6:27] 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

Subselect in a RETURN is now disallowed, just like other table referring
statements in a FUNCTION.