Bug #443 Crash in query with ORDER BY, GROUP BY and subqueries
Submitted: 17 May 2003 11:39 Modified: 19 May 2003 5:10
Reporter: jocelyn fournier (Silver Quality Contributor) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1.1 OS:
Assigned to: Assigned Account CPU Architecture:Any

[17 May 2003 11:39] jocelyn fournier
Description:
The following query crashes the server :

How to repeat:
CREATE TABLE `t1` (
  `id` mediumint(8) unsigned NOT NULL auto_increment,
  `pseudo` varchar(35) NOT NULL default '',
  `email` varchar(60) NOT NULL default '',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `email` (`email`),
  UNIQUE KEY `pseudo` (`pseudo`),
) TYPE=MyISAM CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC;

INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');

SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT b*1);
ERROR 2013: Lost connection to MySQL server during query

However this query works fine :

SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT b);
+-------+-------+
| a     | b     |
+-------+-------+
| test  | test  |
| test1 | test1 |
+-------+-------+
2 rows in set (0.00 sec)

Stack trace :

0x80b2f56 handle_segfault + 710
0x82b0c98 pthread_sighandler + 176
0xc3c9c031 _end + -1149381971
0x80e33d3 JOIN::optimize() + 83
0x809524c subselect_single_select_engine::exec() + 284
0x80935c7 Item_singlerow_subselect::val_str(String*) + 23
0x804d9ab Item::save_in_field(Field*, bool) + 91
0x8051b00 Item_result_field::save_in_result_field(bool) + 32
0x80f0dc6 copy_funcs(Item**) + 38
0x80ede20 end_write(JOIN*, st_join_table*, bool) + 96
0x80eca55 sub_select(JOIN*, st_join_table*, bool) + 245
0x80ec5cf do_select(JOIN*, List<Item>*, st_table*, Procedure*) + 271
0x80e48a3 JOIN::exec() + 851
0x80e5a39 _Z12mysql_selectP3THDPPP4ItemP13st_table_listjR4ListIS1_ES2_jP8st_orderSB_S2_SB_mP13select_resultP18st_select_lex_unitP13st_sel + 377
0x80e2c6f handle_select(THD*, st_lex*, select_result*) + 303
0x80c115a mysql_execute_command(THD*) + 730
0x80c6798 mysql_parse(THD*, char*, unsigned) + 232
0x80bfd31 dispatch_command(enum_server_command, THD*, char*, unsigned) + 945
0x80bf935 do_command(THD*) + 133
0x80bf1b8 handle_one_connection + 792
0x82ae6ba pthread_start_thread + 218
0x82e27ca thread_start + 4
[18 May 2003 10:04] Oleksandr Byelkin
Thank you for bug report. 
I think it is same bug as 442 
(subselect which should be reduced in ORDER clause) 
but I'll test it.
[19 May 2003 4:31] Oleksandr Byelkin
This bug is same with 442. I think it is better to continue only with first one.