Bug #674 DISTINCT ... DESC LIMIT cause "Lost connection..."
Submitted: 18 Jun 2003 12:14 Modified: 25 Jun 2003 5:16
Reporter: Alexey Stroganov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.0.13/14, 4.1.1 OS:Linux (Linux)
Assigned to: Alexey Botchkov CPU Architecture:Any

[18 Jun 2003 12:14] Alexey Stroganov
Description:
I am not sure is it known bug or not.

The query below is ok for 3.23.56 but for 4.0.14 and 4.1.1 from bk it cause
'ERROR 2013: Lost connection to MySQL server during query'.

SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM htmls GROUP BY rin
ORDER BY prod DESC LIMIT 5;

How to repeat:

database schema:

CREATE TABLE htmls (
  date_id int(11) NOT NULL default '0',
  id int(11) default NULL,
  html varchar(5) default NULL,
  rin int(11) default '0',
  out int(11) default '0'
) TYPE=MyISAM;

--
-- Dumping data for table 'htmls'
--

INSERT INTO htmls VALUES (2,1,'1',1,0);

SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM htmls GROUP BY rin
ORDER BY prod DESC LIMIT 5;
[19 Jun 2003 2:50] Alexander Keremidarski
Query result is meaningless, but still it is crashing Bug.

Here is shortest query which triggers it:

SELECT DISTINCT SUM(out)/(SUM(rin)+1) as 'prod' FROM htmls GROUP BY rin;

sql_select.cc:4110

if (!(key_part_info= (KEY_PART_INFO*)
      sql_calloc((keyinfo->key_parts)*sizeof(KEY_PART_INFO))))

sql_calloc() is called with size=4294967272

Before that at sql_select.cc:4027
  keyinfo=param->keyinfo;
[25 Jun 2003 5:16] Alexey Botchkov
Thank you for your bug report. This issue has been fixed in the latest
development tree for that product. You can find more information about
accessing our development trees at 
    http://www.mysql.com/doc/en/Installing_source_tree.html