Bug #10036 Server lost connectin when UDF called with SELECT ... table
Submitted: 20 Apr 2005 17:07 Modified: 26 May 2005 6:50
Reporter: Rudenko Ilya Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: User-defined functions ( UDF ) Severity:S2 (Serious)
Version:5.0.4 OS:Linux (Fedora Core 3)
Assigned to: CPU Architecture:Any

[20 Apr 2005 17:07] Rudenko Ilya
Description:
SELECT udf(params) is ok

when I execute

SELECT columns, udf(param) FROM table_name

client loose connection to server:

ERROR 2013 (HY000): Lost connection to MySQL server during query

How to repeat:
CREATE TABLE `test` (
  `id` smallint(5) unsigned NOT NULL auto_increment,
  `name_en` varchar(255) collate cp1251_ukrainian_ci NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COLLATE=cp1251_ukrainian_ci;

INSERT INTO `test` VALUES (123, 'sdfsdf', '0000-00-00');
INSERT INTO `test` VALUES (124, 'sdfgdfs', '0000-00-00');
INSERT INTO `test` VALUES (125, 'sadfasdfsad', '0000-00-00');
        
delimiter //

CREATE FUNCTION weekday_nom (num INT, lang CHAR(2)) RETURNS char(20) LANGUAGE SQL DETERMINISTIC SQL SECURITY INVOKERBEGIN IF lang = 'ru' THEN RETURN CASE num WHEN 1 THEN 'Monday' END; END IF; END //

SELECT *, weekday_nom(1, 'ru') FROM test;
[20 Apr 2005 17:27] MySQL Verification Team
Your test case shows the below error in the create function:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
IN IF lang = 'ru' THEN RETURN CASE num
WHEN 1 THEN 'Monday' END; END I' at line 2
[20 Apr 2005 20:44] Rudenko Ilya
I make mistake only when I copy code to website, as I sad function executed correctly independent in SELECT weekday_nom(1, 'ru')

CREATE FUNCTION weekday_nom (num INT, lang CHAR(2)) RETURNS char(20)
LANGUAGE SQL DETERMINISTIC SQL SECURITY INVOKER BEGIN IF lang = 'ru'
THEN RETURN CASE num WHEN 1 THEN 'Monday' END; END IF; END //
[20 May 2005 23: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".
[25 May 2005 22:20] MySQL Verification Team
Thank you for the bug report I was able to repeat with bk source:

CREATE TABLE `test` (
  `id` smallint(5) unsigned NOT NULL auto_increment,
  `name_en` varchar(255) collate cp1251_ukrainian_ci NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 COLLATE=cp1251_ukrainian_ci;

INSERT INTO `test` VALUES (123, 'sdfsdf', '0000-00-00');
INSERT INTO `test` VALUES (124, 'sdfgdfs', '0000-00-00');
INSERT INTO `test` VALUES (125, 'sadfasdfsad', '0000-00-00');
        
delimiter //

CREATE FUNCTION weekday_nom (num INT, lang CHAR(2)) RETURNS char(20)
LANGUAGE SQL DETERMINISTIC SQL SECURITY INVOKER BEGIN IF lang = 'ru'
THEN RETURN CASE num WHEN 1 THEN 'Monday' END; END IF; END //

SELECT *, weekday_nom(1, 'ru') FROM test;

On both Slackware Linux and Windows. Below call stack on Windows:

 	mysqld-debug.exe!read_view_sees_trx_id(read_view_struct * view=0x00000000, dulint_struct trx_id={...})  Line 53 + 0x3	C
>	mysqld-debug.exe!lock_clust_rec_cons_read_sees(unsigned char * rec=0x01ef009c, dict_index_struct * index=0x01dbb9a0, const unsigned long * offsets=0x03f7e350, read_view_struct * view=0x00000000)  Line 495 + 0x11	C
 	mysqld-debug.exe!row_search_for_mysql(unsigned char * buf=0x0307d1b0, unsigned long mode=1, row_prebuilt_struct * prebuilt=0x01dbbaa0, unsigned long match_mode=0, unsigned long direction=1)  Line 3736 + 0x31	C
 	mysqld-debug.exe!ha_innobase::general_fetch(unsigned char * buf=0x0307d1b0, unsigned int direction=1, unsigned int match_mode=0)  Line 3886 + 0x17	C++
 	mysqld-debug.exe!ha_innobase::rnd_next(unsigned char * buf=0x0307d1b0)  Line 4076 + 0x10	C++
 	mysqld-debug.exe!rr_sequential(st_read_record * info=0x03093c90)  Line 193 + 0x1b	C++
 	mysqld-debug.exe!sub_select(JOIN * join=0x030988d8, st_join_table * join_tab=0x03093c50, int end_of_records=0)  Line 9246 + 0xa	C++
 	mysqld-debug.exe!do_select(JOIN * join=0x030988d8, List<Item> * fields=0x03076380, st_table * table=0x00000000, Procedure * procedure=0x00000000)  Line 9004 + 0xf	C++
 	mysqld-debug.exe!JOIN::exec()  Line 1658 + 0x19	C++
 	mysqld-debug.exe!mysql_select(THD * thd=0x03076090, Item * * * rref_pointer_array=0x03076418, st_table_list * tables=0x03098608, unsigned int wild_num=1, List<Item> & fields={...}, Item * conds=0x00000000, unsigned int og_num=0, st_order * order=0x00000000, st_order * group=0x00000000, Item * having=0x00000000, st_order * proc_param=0x00000000, unsigned long select_options=2158250496, select_result * result=0x030988c8, st_select_lex_unit * unit=0x030760f0, st_select_lex * select_lex=0x03076308)  Line 2054	C++
 	mysqld-debug.exe!handle_select(THD * thd=0x03076090, st_lex * lex=0x030760d8, select_result * result=0x030988c8, unsigned long setup_tables_done_option=0)  Line 254 + 0x91	C++
 	mysqld-debug.exe!mysql_execute_command(THD * thd=0x03076090)  Line 2395 + 0x13	C++
 	mysqld-debug.exe!mysql_parse(THD * thd=0x03076090, char * inBuf=0x03097ca8, unsigned int length=40)  Line 5254 + 0x9	C++
 	mysqld-debug.exe!dispatch_command(enum_server_command command=COM_QUERY, THD * thd=0x03076090, char * packet=0x0308fbe9, unsigned int packet_length=41)  Line 1653 + 0x1d	C++
 	mysqld-debug.exe!do_command(THD * thd=0x03076090)  Line 1456 + 0x31	C++
 	mysqld-debug.exe!handle_one_connection(void * arg=0x03076090)  Line 1114 + 0x9	C++
 	mysqld-debug.exe!pthread_start(void * param=0x03085170)  Line 63 + 0x7	C
 	mysqld-debug.exe!_threadstart(void * ptd=0x030851a8)  Line 173 + 0xd	C
 	kernel32.dll!7c80b50b() 	
 	kernel32.dll!7c8399f3() 	

I will test with lasted bk source.
[26 May 2005 6:50] Dmitry Lenev
Hi, Ilya!

Thank you for your report!

This is duplicate of bug #10015 "Crash in InnoDB if SPs and Triggers are used"
(see http://bugs.mysql.com/bug.php?id=10015) on which I am working now.