Bug #11013 Server crashes when referencing view containing a function
Submitted: 1 Jun 2005 9:38 Modified: 1 Jun 2005 12:51
Reporter: Ulrich Weber Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.4-beta-nt OS:Windows (WinXP Pro SP1)
Assigned to: CPU Architecture:Any

[1 Jun 2005 9:38] Ulrich Weber
Description:
A view was successfully defined referencing a user defined function as well as a column from a table and. When referencing the view in a SELECT Staement, the server crashes.

How to repeat:
Execute the following script from the command line client:

USE test;
DROP TABLE IF EXISTS t_tab;
CREATE TABLE `t_tab` (
  `auth_upd` tinyint(1) default NULL,
  `id` int(11) NOT NULL default '0',
  `resp_upd` tinyint(1) default NULL,
  `Sort` int(11) default NULL,
  `Status` varchar(50) default NULL,
  `v_mgr_upd` tinyint(1) default NULL,
  `t_s` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `t_tab` (`auth_upd`,`id`,`resp_upd`,`Sort`,`Status`,`v_mgr_upd`,`t_s`) VALUES 
 (-1,0,0,0,'new',0,'2005-05-24 22:51:13'),
 (-1,1,-1,1,'released',0,'2005-05-24 22:51:13'),
 (-1,2,-1,2,'processing',0,'2005-05-24 22:51:13'),
 (0,3,-1,3,'prepared',-1,'2005-05-24 22:51:13'),
 (-1,4,-1,4,'finished',0,'2005-05-24 22:51:13'),
 (0,5,0,5,'closed',0,'2005-05-24 22:51:13'),
 (0,6,0,6,'rejected',0,'2005-05-24 22:51:13');
DROP FUNCTION IF EXISTS t_func;
CREATE FUNCTION t_func() RETURNS int(11) return 2;
DROP VIEW IF EXISTS t_view;
CREATE VIEW t_view AS select t_func() AS func, t_tab.* FROM t_tab;
SELECT * FROM t_view;

The response from the command line client will be:

Database changed
Query OK, 0 rows affected (0.34 sec)
Query OK, 0 rows affected (0.12 sec)
Query OK, 7 rows affected (0.04 sec)
Records: 7  Duplicates: 0  Warnings: 0
Query OK, 0 rows affected (0.03 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
ERROR 2013 (HY000): Lost connection to MySQL server during query

Afterwards Windows will announce, that the MySQL Server had to be stopped.
[1 Jun 2005 12:45] MySQL Verification Team
Thank you for the bug report. I was able to repeat, it is crashes at the
same point as another bug report (will investigate for duplicate).

 	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=0x01ef40a5, dict_index_struct * index=0x01dbcda0, const unsigned long * offsets=0x03f7e350, read_view_struct * view=0x00000000)  Line 495 + 0x11	C
 	mysqld-debug.exe!row_search_for_mysql(unsigned char * buf=0x00fcd738, unsigned long mode=1, row_prebuilt_struct * prebuilt=0x01dbdca0, unsigned long match_mode=0, unsigned long direction=1)  Line 3736 + 0x31	C
 	mysqld-debug.exe!ha_innobase::general_fetch(unsigned char * buf=0x00fcd738, unsigned int direction=1, unsigned int match_mode=0)  Line 3886 + 0x17	C++
 	mysqld-debug.exe!ha_innobase::rnd_next(unsigned char * buf=0x00fcd738)  Line 4076 + 0x10	C++
 	mysqld-debug.exe!rr_sequential(st_read_record * info=0x03099368)  Line 193 + 0x1b	C++
 	mysqld-debug.exe!sub_select(JOIN * join=0x03098050, st_join_table * join_tab=0x03099328, int end_of_records=0)  Line 9242 + 0xa	C++
 	mysqld-debug.exe!do_select(JOIN * join=0x03098050, List<Item> * fields=0x0307c440, st_table * table=0x00000000, Procedure * procedure=0x00000000)  Line 9000 + 0xf	C++
 	mysqld-debug.exe!JOIN::exec()  Line 1658 + 0x19	C++
 	mysqld-debug.exe!mysql_select(THD * thd=0x0307c150, Item * * * rref_pointer_array=0x0307c4d8, st_table_list * tables=0x03091098, 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=0x03092cb8, st_select_lex_unit * unit=0x0307c1b0, st_select_lex * select_lex=0x0307c3c8)  Line 2054	C++
 	mysqld-debug.exe!handle_select(THD * thd=0x0307c150, st_lex * lex=0x0307c198, select_result * result=0x03092cb8, unsigned long setup_tables_done_option=0)  Line 254 + 0x91	C++
 	mysqld-debug.exe!mysql_execute_command(THD * thd=0x0307c150)  Line 2400 + 0x13	C++
 	mysqld-debug.exe!mysql_parse(THD * thd=0x0307c150, char * inBuf=0x03090fa8, unsigned int length=20)  Line 5260 + 0x9	C++
 	mysqld-debug.exe!dispatch_command(enum_server_command command=COM_QUERY, THD * thd=0x0307c150, char * packet=0x03088ee9, unsigned int packet_length=21)  Line 1653 + 0x1d	C++
 	mysqld-debug.exe!do_command(THD * thd=0x0307c150)  Line 1456 + 0x31	C++
 	mysqld-debug.exe!handle_one_connection(void * arg=0x0307c150)  Line 1114 + 0x9	C++
 	mysqld-debug.exe!pthread_start(void * param=0x03086a40)  Line 63 + 0x7	C
 	mysqld-debug.exe!_threadstart(void * ptd=0x0307deb0)  Line 173 + 0xd	C
 	kernel32.dll!7c80b50b() 	
 	kernel32.dll!7c8399f3()
[1 Jun 2005 12:51] MySQL Verification Team
Related to the same cause as:

http://bugs.mysql.com/bug.php?id=10760
[1 Jun 2005 13:20] Dmitry Lenev
Actually judjing from the bug description and stacktrace I would say that this 
is duplicate of http://bugs.mysql.com/bug.php?id=10015.