Bug #53450 Crash / assertion "virtual int ha_myisam::index_first(uchar*)") at assert.c:81
Submitted: 5 May 2010 23:05 Modified: 14 Oct 2010 14:56
Reporter: Patrick Crews Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:mysql-next-mr/5.1 OS:Any
Assigned to: Gleb Shchepa CPU Architecture:Any
Tags: assertion, crashing bug, delete, myisam

[5 May 2010 23:05] Patrick Crews
Description:
Crash / assertion fail in mysql-next-mr.  This only occurs with MyISAM and not Innodb tables

NOTE:  This bug appears to go away when the patch for Bug#36569 is applied.  However this patch is still in QA review and this needs to be documented in the meantime.

This query:
 DELETE  
FROM M  
WHERE  2  AND `col_varchar_10_utf8_key`  IN ( 'b' )  OR `pk`  =  10  
ORDER  BY `col_int_key`  
LIMIT  1   ;

Causes the following backtrace.  
Thread 1 (Thread 30602):
#0  0x00616422 in __kernel_vsyscall ()
#1  0x00900e93 in __pthread_kill (threadid=3018472304, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:64
#2  0x08d2e792 in my_write_core (sig=6) at stacktrace.c:326
#3  0x083d7370 in handle_segfault (sig=6) at mysqld.cc:2786
#4  <signal handler called>
#5  0x00616422 in __kernel_vsyscall ()
#6  0x002a84d1 in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#7  0x002ab932 in *__GI_abort () at abort.c:92
#8  0x002a1648 in *__GI___assert_fail (assertion=0x8fd94d7 "inited==INDEX", file=0x8fd8d54 "ha_myisam.cc", line=1618, 
    function=0x8fd97c0 "virtual int ha_myisam::index_first(uchar*)") at assert.c:81
#9  0x08b1f70b in ha_myisam::index_first (this=0xa5d9798, buf=0xa5d98b0 "\377") at ha_myisam.cc:1618
#10 0x08665674 in rr_index_first (info=0xb3ea184c) at records.cc:359
#11 0x0857c9b6 in mysql_delete (thd=0xa55d2d0, table_list=0xa5e11d8, conds=0xa5e1ad8, order=0xa55e77c, limit=1, options=0, 
    reset_auto_increment=false) at sql_delete.cc:319
#12 0x0840206e in mysql_execute_command (thd=0xa55d2d0) at sql_parse.cc:3298
#13 0x08410717 in mysql_parse (thd=0xa55d2d0, 
    inBuf=0xa5e1070 "DELETE  \nFROM M  \nWHERE  2  AND `col_varchar_10_utf8_key`  IN ( 'b' )  OR `pk`  =  10  \nORDER  BY `col_int_key`  \nLIMIT  1", length=122, found_semicolon=0xb3ea2e58) at sql_parse.cc:5811
#14 0x083f734e in dispatch_command (command=COM_QUERY, thd=0xa55d2d0, 
    packet=0xa5d5089 "DELETE  \nFROM M  \nWHERE  2  AND `col_varchar_10_utf8_key`  IN ( 'b' )  OR `pk`  =  10  \nORDER  BY `col_int_key`  \nLIMIT  1   ", packet_length=125) at sql_parse.cc:1088
#15 0x083f5baa in do_command (thd=0xa55d2d0) at sql_parse.cc:774
#16 0x083f22f5 in do_handle_one_connection (thd_arg=0xa55d2d0) at sql_connect.cc:1188
#17 0x083f1fb5 in handle_one_connection (arg=0xa55d2d0) at sql_connect.cc:1127
#18 0x08cd8eb3 in pfs_spawn_thread (arg=0xa610c38) at pfs.cc:1011
#19 0x008fb80e in start_thread (arg=0xb3ea3b70) at pthread_create.c:300
#20 0x0034a8de in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130

How to repeat:
MTR test case:
#/* Begin test case for query 0 */

--disable_warnings
DROP TABLE /*! IF EXISTS */ M;
--enable_warnings

CREATE TABLE `M` (
  `col_varchar_10_utf8_key` varchar(10) CHARACTER SET utf8 DEFAULT NULL,
  `pk` int(11) NOT NULL AUTO_INCREMENT,
  `col_int_key` int(11) DEFAULT NULL,
  PRIMARY KEY (`pk`),
  KEY `col_varchar_10_utf8_key` (`col_varchar_10_utf8_key`),
  KEY `col_int_key` (`col_int_key`),
  KEY `test_idx` (`col_int_key`,`pk`) USING HASH
) ENGINE=MyISAM AUTO_INCREMENT=100 DEFAULT CHARSET=latin1;
INSERT INTO `M` VALUES ('q',2,4);
INSERT INTO `M` VALUES ('z',7,9);
INSERT INTO `M` VALUES (NULL,9,4);
INSERT INTO `M` VALUES ('l',12,7);
INSERT INTO `M` VALUES ('r',13,4);
INSERT INTO `M` VALUES ('o',14,4);
INSERT INTO `M` VALUES ('i',21,4);
INSERT INTO `M` VALUES ('t',23,5);
INSERT INTO `M` VALUES ('e',27,4);
INSERT INTO `M` VALUES (NULL,28,4);
INSERT INTO `M` VALUES ('j',29,4);
INSERT INTO `M` VALUES (NULL,32,4);
INSERT INTO `M` VALUES (NULL,35,4);
INSERT INTO `M` VALUES (NULL,36,2);
INSERT INTO `M` VALUES ('m',39,9);
INSERT INTO `M` VALUES (NULL,40,4);
INSERT INTO `M` VALUES ('a',42,2);
INSERT INTO `M` VALUES (NULL,44,5);
INSERT INTO `M` VALUES ('o',47,4);
INSERT INTO `M` VALUES ('h',48,4);
INSERT INTO `M` VALUES (NULL,51,4);
INSERT INTO `M` VALUES ('v',53,4);
INSERT INTO `M` VALUES ('o',54,2);
INSERT INTO `M` VALUES ('q',57,4);
INSERT INTO `M` VALUES ('g',59,4);
INSERT INTO `M` VALUES ('j',60,4);
INSERT INTO `M` VALUES ('l',61,4);
INSERT INTO `M` VALUES ('z',62,2);
INSERT INTO `M` VALUES ('u',63,5);
INSERT INTO `M` VALUES ('j',65,9);
INSERT INTO `M` VALUES ('s',68,4);
INSERT INTO `M` VALUES (NULL,69,5);
INSERT INTO `M` VALUES ('g',72,2);
INSERT INTO `M` VALUES (NULL,74,4);
INSERT INTO `M` VALUES ('d',75,4);
INSERT INTO `M` VALUES (NULL,76,4);
INSERT INTO `M` VALUES ('o',77,4);
INSERT INTO `M` VALUES ('y',79,4);
INSERT INTO `M` VALUES ('n',80,4);
INSERT INTO `M` VALUES ('h',82,4);
INSERT INTO `M` VALUES ('o',83,9);
INSERT INTO `M` VALUES (NULL,84,4);
INSERT INTO `M` VALUES ('z',86,1);
INSERT INTO `M` VALUES (NULL,87,4);
INSERT INTO `M` VALUES ('y',88,4);
INSERT INTO `M` VALUES ('t',89,1);
INSERT INTO `M` VALUES ('i',90,4);
INSERT INTO `M` VALUES ('z',91,4);
INSERT INTO `M` VALUES ('y',92,1);
INSERT INTO `M` VALUES ('t',93,4);
INSERT INTO `M` VALUES ('i',94,9);
INSERT INTO `M` VALUES ('t',95,5);
INSERT INTO `M` VALUES (NULL,96,1);
INSERT INTO `M` VALUES (NULL,97,4);
INSERT INTO `M` VALUES ('a',99,4);

 DELETE  
FROM M  
WHERE  2  AND `col_varchar_10_utf8_key`  IN ( 'b' )  OR `pk`  =  10  
ORDER  BY `col_int_key`  
LIMIT  1   ;

DROP TABLE M;
#/* End of test case for query 0 */
[5 May 2010 23:06] Patrick Crews
Full crash output

Attachment: Bug53450_backtrace.txt (text/plain), 8.79 KiB.

[5 May 2010 23:23] MySQL Verification Team
miguel@hegel:~$ dbs/5.1/libexec/mysqld
100505 20:01:02 [Note] Plugin 'FEDERATED' is disabled.
100505 20:01:02 [Note] Plugin 'ndbcluster' is disabled.
100505 20:01:03  InnoDB: Started; log sequence number 0 44233
100505 20:01:03 [Note] Event Scheduler: Loaded 0 events
100505 20:01:03 [Note] dbs/5.1/libexec/mysqld: ready for connections.
Version: '5.1.47-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
100505 20:18:14 [Note] Got signal 15 to shutdown mysqld
100505 20:18:14 [Note] dbs/5.1/libexec/mysqld: Normal shutdown

100505 20:18:14 [Note] Event Scheduler: Purging the queue. 0 events
100505 20:18:16  InnoDB: Starting shutdown...
100505 20:18:19  InnoDB: Shutdown completed; log sequence number 0 44233
100505 20:18:19 [Note] dbs/5.1/libexec/mysqld: Shutdown complete

miguel@hegel:~$ dbs/5.1/libexec/mysqld
100505 20:19:28 [Note] Plugin 'FEDERATED' is disabled.
100505 20:19:28 [Note] Plugin 'ndbcluster' is disabled.
100505 20:19:28  InnoDB: Started; log sequence number 0 44233
100505 20:19:28 [Note] Event Scheduler: Loaded 0 events
100505 20:19:28 [Note] dbs/5.1/libexec/mysqld: ready for connections.
Version: '5.1.47-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
mysqld: ha_myisam.cc:1706: virtual int ha_myisam::index_first(uchar*): Assertion `inited==INDEX' failed.
100505 20:19:45 - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
[5 May 2010 23:26] MySQL Verification Team
Thank you for the bug report, verified as described.
[14 May 2010 10:19] Gleb Shchepa
The bug is similar to the old bug #14272 for UPDATE and it has a similar fix:

=== modified file 'sql/sql_delete.cc'
--- old/sql/sql_delete.cc	2010-05-12 11:19:12 +0000
+++ new/sql/sql_delete.cc	2010-05-14 10:18:53 +0000
@@ -266,7 +266,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
     free_underlaid_joins(thd, select_lex);
     DBUG_RETURN(TRUE);
   }
-  if (usable_index==MAX_KEY)
+  if (usable_index==MAX_KEY || (select && select->quick))
     init_read_record(&info, thd, table, select, 1, 1, FALSE);
   else
     init_read_record_idx(&info, thd, table, 1, usable_index);
[14 May 2010 11:38] 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/108321

3382 Gleb Shchepa	2010-05-14
      Bug #53450: Crash / assertion "virtual int
                  ha_myisam::index_first(uchar*)") at assert.c:81
      
      Single-table DELETE crash/assertion similar to single-table
      UPDATE bug 14272.
      
      Same resolution as for the bug 14272:
      Don't run index scan when we should use quick select.
      This could cause failures because there are table handlers (like federated)
      that support quick select scanning but do not support index scanning.
     @ mysql-test/r/delete.result
        Test case for bug #53450.
     @ mysql-test/t/delete.test
        Test case for bug #53450.
     @ sql/sql_delete.cc
        Bug #53450: Crash / assertion "virtual int
                    ha_myisam::index_first(uchar*)") at assert.c:81
        
        The mysql_delete function has been modified to not to use
        init_read_record_idx instead of init_read_record for the
        quick select.
[28 May 2010 5:50] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100524190136-egaq7e8zgkwb9aqi) (version source revid:alik@sun.com-20100524190136-egaq7e8zgkwb9aqi) (pib:16)
[28 May 2010 6:19] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100524190941-nuudpx60if25wsvx) (version source revid:alik@sun.com-20100524190409-5w4l7mje1wk1c90l) (merge vers: 6.0.14-alpha) (pib:16)
[28 May 2010 6:47] Bugs System
Pushed into 5.5.5-m3 (revid:alik@sun.com-20100524185725-c8k5q7v60i5nix3t) (version source revid:alexey.kopytov@sun.com-20100523204118-0tl3goawu658rxh6) (merge vers: 5.5.5-m3) (pib:16)
[2 Jun 2010 8:50] Bugs System
Pushed into 5.1.48 (revid:georgi.kodinov@oracle.com-20100602084411-2yu607bslbmgufl3) (version source revid:gshchepa@mysql.com-20100514113627-un2o7ndffsc9uy9e) (merge vers: 5.1.47) (pib:16)
[10 Jun 2010 18:29] Paul DuBois
Noted in 5.1.48, 5.5.5, 6.0.14 changelogs.

For single-table DELETE statements that used quick select and index
scan simultaneously caused a server crash or assertion failure.
[14 Oct 2010 8:35] Bugs System
Pushed into mysql-5.1-telco-7.0 5.1.51-ndb-7.0.20 (revid:martin.skold@mysql.com-20101014082627-jrmy9xbfbtrebw3c) (version source revid:vasil.dimov@oracle.com-20100513074652-0cvlhgkesgbb2bfh) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 8:50] Bugs System
Pushed into mysql-5.1-telco-6.3 5.1.51-ndb-6.3.39 (revid:martin.skold@mysql.com-20101014083757-5qo48b86d69zjvzj) (version source revid:vasil.dimov@oracle.com-20100513074652-0cvlhgkesgbb2bfh) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 9:05] Bugs System
Pushed into mysql-5.1-telco-6.2 5.1.51-ndb-6.2.19 (revid:martin.skold@mysql.com-20101014084420-y54ecj85j5we27oa) (version source revid:vasil.dimov@oracle.com-20100513074652-0cvlhgkesgbb2bfh) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 14:56] Jon Stephens
Already documented in the 5.1.48 changelog; no new changelog entries required. setting back to Closed state.