Bug #32556 assert in "using index for group-by" : is_last_prefix <= 0, file .\opt_range.cc
Submitted: 21 Nov 2007 5:11 Modified: 14 Jan 2008 18:59
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S1 (Critical)
Version:5.0.50,5.1.23,6.0.3 OS:Any
Assigned to: Gleb Shchepa CPU Architecture:Any
Tags: assertion

[21 Nov 2007 5:11] Shane Bester
Description:
crash when grouping by a bit column and the explain shows using an index for group-by:

Version: '5.1.23-rc-debug'  socket: ''  port: 3307  Source distribution
Assertion failed: is_last_prefix <= 0, file .\opt_range.cc, line 10421

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

mysqld.exe!_NMSG_WRITE
mysqld.exe!abort
mysqld.exe!_wassert
mysqld.exe!QUICK_GROUP_MIN_MAX_SELECT::get_next
mysqld.exe!rr_quick
mysqld.exe!join_init_read_record
mysqld.exe!sub_select
mysqld.exe!do_select
mysqld.exe!JOIN::exec
mysqld.exe!mysql_select
mysqld.exe!handle_select
mysqld.exe!execute_sqlcom_select
mysqld.exe!mysql_execute_command
mysqld.exe!mysql_parse
mysqld.exe!dispatch_command
mysqld.exe!do_command
mysqld.exe!handle_one_connection
mysqld.exe!pthread_start
mysqld.exe!_callthreadstart
mysqld.exe!_threadstart

release binary may hang indefinitely or return infinite results, debug binary will assert immediately.

How to repeat:
drop table if exists `t1`;
create table `t1`(`a` bit(13),key(`a`))engine=myisam;
insert into `t1`(`a`) values (65535),(65525),(65535),(65535),(65535),(65535),(65535),(65535),(65535),(65535);
explain select 1 from `t1` group by `a`;
select 1 from `t1` group by `a`;
[21 Nov 2007 5:28] Valeriy Kravchuk
On 5.0.44 (after replacing bit(13) with bit(24)) I've got:

mysql> explain select 1 from `t1` group by `a`\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: t1
         type: range
possible_keys: NULL
          key: a
      key_len: 4
          ref: NULL
         rows: 6
        Extra: Using index for group-by
1 row in set (0.00 sec)

mysql> select 1 from `t1` group by `a`;
+---+
| 1 |
+---+
| 1 |
| 1 |
+---+
2 rows in set (0.06 sec)

Correct results. So, it is a regression.
[21 Nov 2007 18:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/38234

ChangeSet@1.2578, 2007-11-21 22:56:42+04:00, gshchepa@gleb.loc +3 -0
  Fixed bug #32556: assert in "using index for group-by" :
                    is_last_prefix <= 0, file .\opt_range.cc.
  
  SELECT ... GROUP BY bit field failed with an assertion if the
  bit length of that field was not divisible by 8.
[14 Dec 2007 8:15] Bugs System
Pushed into 5.0.54
[14 Dec 2007 8:18] Bugs System
Pushed into 5.1.23-rc
[14 Dec 2007 8:21] Bugs System
Pushed into 6.0.5-alpha
[14 Jan 2008 18:59] Jon Stephens
Documented in the 5.0.54, 5.1.23, and 6.0.5 changelogs as:

        A SELECT ... GROUP BY bit_column query failed with an
        assertion if the length of the BIT column used for the GROUP BY was
        not an integer multiple of 8.