Bug #11537 Server crashes when running a SELECT DISTINCT with a WHERE BETWEEN clause
Submitted: 23 Jun 2005 23:02 Modified: 23 Jun 2005 23:17
Reporter: Johnvey Hwang Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.12 standard OS:MacOS (Mac OS X 10.4.2)
Assigned to: CPU Architecture:Any

[23 Jun 2005 23:02] Johnvey Hwang
Description:
The server crashes when running the following query from the mysql console:

------------
SELECT DISTINCT tpages.xar_pid, tpages.xar_name, tpages.xar_desc, tpages.xar_itemtype, tpages.xar_parent, tpages.xar_left, tpages.xar_right, tpages.xar_template, tpages.xar_status, tpages.xar_encode_url, tpages.xar_decode_url, tpages.xar_theme, tpages.xar_function, tpages.xar_page_template FROM xar_xarpages_pages AS tpages WHERE tpages.xar_status IN ('ACTIVE','EMPTY') AND tpages.xar_left between 2 AND 3 ORDER BY tpages.xar_left ASC
------------

The error file shows the following result afterwards:

------------
mysqld got signal 10;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=8388600
read_buffer_size=131072
max_used_connections=1
max_connections=100
threads_connected=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 225791 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

050623 15:43:10  mysqld restarted
-----------

This query works fine on 4.1.11 (on OSX 10.4.2), with the same exact dataset. Removing either the "DISTINCT" or "between 2 AND 3" clauses makes the query work.  Alternatively, replacing the "between 2 AND 3" clause with a "IN(2,3)" also fails.  Using a "= 2" does work.

How to repeat:
Create the following table:
-------
CREATE TABLE `xar_xarpages_pages` (
  `xar_pid` int(11) NOT NULL auto_increment,
  `xar_name` varchar(100) NOT NULL default '',
  `xar_desc` longtext,
  `xar_itemtype` int(11) NOT NULL default '0',
  `xar_parent` int(11) NOT NULL default '0',
  `xar_left` int(11) NOT NULL default '0',
  `xar_right` int(11) NOT NULL default '0',
  `xar_template` varchar(100) default NULL,
  `xar_page_template` varchar(100) default NULL,
  `xar_theme` varchar(100) default NULL,
  `xar_encode_url` varchar(100) default NULL,
  `xar_decode_url` varchar(100) default NULL,
  `xar_function` varchar(100) default NULL,
  `xar_status` varchar(20) NOT NULL default 'ACTIVE',
  `xar_alias` tinyint(4) NOT NULL default '0',
  PRIMARY KEY  (`xar_pid`),
  KEY `i_xar_xarpages_page_left` (`xar_left`),
  KEY `i_xar_xarpages_page_name` (`xar_name`),
  KEY `i_xar_xarpages_page_type` (`xar_itemtype`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
------

Insert some data:

-------
INSERT INTO `xar_xarpages_pages` VALUES (1,'beta_sign_up','',2,0,2,3,'signup','','','','','submit_newuser','ACTIVE',0),(3,'back_talk','',2,0,14,15,'backtalk','','','','','submit_bugreport','ACTIVE',0),(4,'support_ticket','',2,0,12,13,'support','','','','','submit_bugreport','ACTIVE',0),(5,'beta_enrollment','',2,0,10,11,'enroll','','','','','beta_enroll','ACTIVE',0);
-------

And run the above query.

Suggested fix:
Wish I knew! So far, running 4.1.11 is the only option.
[23 Jun 2005 23:17] MySQL Verification Team
I was unable to repeat on Linux Slackware with latest Bk source:

mysql> SELECT DISTINCT tpages.xar_pid, tpages.xar_name, tpages.xar_desc, tpages.xar_itemtype, tpages.xar_parent, tpages.xar_left, tpages.xar_right, tpages.xar_template, tpages.xar_status, tpages.xar_encode_url, tpages.xar_decode_url, tpages.xar_theme, tpages.xar_function, tpages.xar_page_template FROM xar_xarpages_pages AS tpages WHERE tpages.xar_status IN ('ACTIVE','EMPTY') AND tpages.xar_left between 2 AND 3 ORDER BY tpages.xar_left ASC\G
*************************** 1. row ***************************
          xar_pid: 1
         xar_name: beta_sign_up
         xar_desc: 
     xar_itemtype: 2
       xar_parent: 0
         xar_left: 2
        xar_right: 3
     xar_template: signup
       xar_status: ACTIVE
   xar_encode_url: 
   xar_decode_url: 
        xar_theme: 
     xar_function: submit_newuser
xar_page_template: 
1 row in set (0.01 sec)

mysql> select version();
+--------------+
| version()    |
+--------------+
| 4.1.13-debug |
+--------------+
1 row in set (0.00 sec)