Bug #62 Crash with SELECT COUNT(DISTINCT()) in MySQL 4.0.11
Submitted: 9 Feb 2003 12:28 Modified: 14 Feb 2003 10:56
Reporter: jocelyn fournier (Silver Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S1 (Critical)
Version:4.0.11-bk OS:Any (all)
Assigned to: Sergei Golubchik CPU Architecture:Any

[9 Feb 2003 12:28] jocelyn fournier
Description:
MySQL crashes if a SELECT COUNT(DISTINCT(field)) FROM table is used.

How to repeat:
CREATE TABLE `moderationcrazycity` (
  `victime` mediumint(8) unsigned NOT NULL default '0',
  `modo` char(35) NOT NULL default '',
  `ipmodo` int(10) unsigned NOT NULL default '0',
  `cat` smallint(4) unsigned NOT NULL default '0',
  `ban` tinyint(1) unsigned NOT NULL default '0',
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  `raison` char(255) NOT NULL default '',
  PRIMARY KEY  (`victime`,`cat`,`ban`),
  KEY `modo` (`modo`,`ban`),
  KEY `victime` (`victime`,`modo`)
) TYPE=MyISAM

SELECT count(distinct(victime)) FROM moderationcrazycity WHERE modo =
'bardass'
ERROR 2013: Lost connection to MySQL server during query

Stack trace :

0x80943a7 handle_segfault + 487
0x826c618 pthread_sighandler + 176
0x80c0443 copy_fields(TMP_TABLE_PARAM*) + 35
0x80527f1 Item_sum_count_distinct::add() + 49
0x8052767 Item_sum_count_distinct::reset() + 39
0x8053694 Item_sum::no_rows_in_result() + 20
0x80c22fb return_zero_rows(JOIN*, select_result*, st_table_list*,
List<Item>&, bool, unsigned, char const*, Item*, Procedure*) + 251
0x80bc34b mysql_select(THD*, st_table_list*, List<Item>&, Item*, st_order*,
st_order*, Item*, st_order*, unsigned long, select_result*) + 1883
0x80bbbdf handle_select(THD*, st_lex*, select_result*) + 175
0x80a101d mysql_execute_command() + 733
0x80a5a59 mysql_parse(THD*, char*, unsigned) + 329
0x809feea dispatch_command(enum_server_command, THD*, char*, unsigned) +
1162
0x809fa19 do_command(THD*) + 121
0x809f2e8 handle_one_connection + 888
0x826a03a pthread_start_thread + 218
0x829da4a thread_start + 4