Bug #55472 Assertion failed in heap_rfirst function of hp_rfirst.c on DELETE statement
Submitted: 22 Jul 2010 8:04 Modified: 12 Aug 2010 19:29
Reporter: John Embretsen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S1 (Critical)
Version:5.5.6-m3-Celosia OS:Any
Assigned to: Gleb Shchepa CPU Architecture:Any
Triage: Triaged: D1 (Critical)

[22 Jul 2010 8:04] John Embretsen
Description:
When executing a single-threaded Random Query Generator test using partitioning against a debug build of MySQL Server, the server asserts with the following message:

Assertion failed: 0, file /export/home/tmp/je159969/mysql-dev/bzr-repos/mysql-trunk-bugfixing/storage/heap/hp_rfirst.c, line 65
100722  9:47:04 - mysqld got signal 6 ;

Stack trace:

 [12] _assert(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff1fdc95 
 [13] heap_rfirst(info = 0x380c500, record = 0x233bfc2 "3^B", inx = 0), line 65 in "hp_rfirst.c"
 [14] ha_heap::index_first(this = 0x38ca580, buf = 0x233bfc2 "3^B"), line 353 in "ha_heap.cc"
 [15] ha_partition::handle_ordered_index_scan(this = 0x38ca190, buf = 0x38ca4b8 "ÿ", reverse_order = false), line 4873 in "ha_partition.cc"
 [16] ha_partition::common_first_last(this = 0x38ca190, buf = 0x38ca4b8 "ÿ"), line 4336 in "ha_partition.cc"
 [17] ha_partition::index_first(this = 0x38ca190, buf = 0x38ca4b8 "ÿ"), line 4285 in "ha_partition.cc"
 [18] rr_index_first(info = 0xfffffd7fff039390), line 362 in "records.cc"
 [19] mysql_delete(thd = 0x37675d0, table_list = 0x37727c0, conds = 0x3772e78, order_list = 0x37695f0, limit = 1ULL, options = 0), line 297 in "sql_delete.cc"
 [20] mysql_execute_command(thd = 0x37675d0), line 3355 in "sql_parse.cc"
 [21] mysql_parse(thd = 0x37675d0, inBuf = 0x3772660 "DELETE FROM v WHERE `col_int_nokey` = 6 ORDER BY `col_int_key` , `col_int_nokey` LIMIT 1", length = 88U, parser_state = 0xfffffd7fff03cab8), line 5901 in "sql_parse.cc"
 [22] dispatch_command(command = COM_QUERY, thd = 0x37675d0, packet = 0x376e631 "DELETE FROM v WHERE `col_int_nokey` = 6 ORDER BY `col_int_key` , `col_int_nokey` LIMIT 1", packet_length = 88U), line 1135 in "sql_parse.cc"
 [23] do_command(thd = 0x37675d0), line 807 in "sql_parse.cc"
 [24] do_handle_one_connection(thd_arg = 0x37675d0), line 1191 in "sql_connect.cc"
 [25] handle_one_connection(arg = 0x37675d0), line 1130 in "sql_connect.cc"
 [26] _thrp_setup(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff27acf5 
 [27] _lwp_start(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff27afb0 

Related code (in storage/heap/hp_rfirst.c) is:

    if (!(info->s->records))
    {
      my_errno=HA_ERR_END_OF_FILE;
      DBUG_RETURN(my_errno);
    }
    DBUG_ASSERT(0); /* TODO fix it */
    info->current_record=0;
    info->current_hash_ptr=0;
    info->update=HA_STATE_PREV_FOUND;
    DBUG_RETURN(heap_rnext(info,record));

Note the "TODO fix it" comment at the line of the assertion that was hit.

Also note that the test fails differently with a non-debug build.

Observed against mysql-trunk-bugfixing as of 2010-07-20 (revid 	jonathan.perkin@oracle.com-20100720093555-gqyrtmkgwrjfgsmc).

How to repeat:
Obtain a debug build of MySQL Server, using a recent development version (trunk or next-mr). This is referred to as $CODE below.

Obtain the RQG:

bzr branch lp:randgen
cd randgen

Run the test:

perl ./runall-new.pl \
--threads=1 \
--grammar=conf/partitioning/partitions-ddl.yy \
--queries=100000 \
--duration=600 \
--basedir=$CODE \
--Reporter=Backtrace

(Note that using runall-new.pl instead of runall.pl is required at this time due to Bug#54835. Alternatively, the suggested patch for that bug can be applied to allow use of runall.pl.)

Note that the test fails like this with a debug build only. With a non-debug build the test triggers a different crash (although it may be related).

Not repeatable against mysql-5.1-bugteam.
[22 Jul 2010 8:58] Sveta Smirnova
Thank you for the report.

Verified as described with mysql-trunk-bugfixing
[22 Jul 2010 12:25] John Embretsen
For the record: Unable to repeat issue (different crash) with non-debug builds (as mentioned above) at this time.
[28 Jul 2010 17:47] 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/114554

3156 Gleb Shchepa	2010-07-28
      Bug #55472: Assertion failed in heap_rfirst function of hp_rfirst.c on    
                  DELETE statement                                                                         
                                                                                                           
      Single-table delete ordered by a field that has a hash-type index                                    
      may cause an assertion failure or a crash.                                                           
                                                                                                           
      An optimization added by the fix for the bug 36569 forced the                                        
      optimizer to use ORDER BY-compatible indices when applicable.                                        
                                                                                                           
      However, the existence of unsorted indices (HASH index algorithm                                     
      for some engines such as HEAP, MEMORY, NDB) was ignored.                                             
                                                                                                           
      The test_if_order_by_key function has been modified to skip                                          
      unsorted indices.                                                 
     @ mysql-test/r/heap_hash.result
        Test case for bug #55472.
     @ mysql-test/t/heap_hash.test
        Test case for bug #55472.
     @ sql/sql_select.cc
        Bug #55472: Assertion failed in heap_rfirst function of hp_rfirst.c on                               
                    DELETE statement                                                                         
                                                                                                             
        The test_if_order_by_key function has been modified to skip                                          
        unsorted indices.
[29 Jul 2010 7:17] 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/114588

3158 Gleb Shchepa	2010-07-29
      Bug #55472: Assertion failed in heap_rfirst function of hp_rfirst.c on
                  DELETE statement
      
      Single-table delete ordered by a field that has a hash-type index
      may cause an assertion failure or a crash.
      
      An optimization added by the fix for the bug 36569 forced the
      optimizer to use ORDER BY-compatible indices when applicable.
      
      However, the existence of unsorted indices (HASH index algorithm
      for some engines such as MEMORY/HEAP, NDB) was ignored.
      
      The test_if_order_by_key function has been modified to skip
      unsorted indices.
     @ mysql-test/r/heap_hash.result
        Test case for bug #55472.
     @ mysql-test/t/heap_hash.test
        Test case for bug #55472.
     @ sql/sql_select.cc
        Bug #55472: Assertion failed in heap_rfirst function of hp_rfirst.c on
                    DELETE statement
        
        The test_if_order_by_key function has been modified to skip
        unsorted indices.
[4 Aug 2010 7:50] Bugs System
Pushed into mysql-trunk 5.5.6-m3 (revid:alik@sun.com-20100731131027-1n61gseejyxsqk5d) (version source revid:marko.makela@oracle.com-20100621094008-o9fa153s3f09merw) (merge vers: 5.1.49) (pib:18)
[4 Aug 2010 8:09] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804080001-bny5271e65xo34ig) (version source revid:marko.makela@oracle.com-20100621094008-o9fa153s3f09merw) (merge vers: 5.1.49) (pib:18)
[4 Aug 2010 8:25] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804081533-c1d3rbipo9e8rt1s) (version source revid:marko.makela@oracle.com-20100621094008-o9fa153s3f09merw) (merge vers: 5.1.49) (pib:18)
[4 Aug 2010 9:04] Bugs System
Pushed into mysql-next-mr (revid:alik@ibmvm-20100804081630-ntapn8bf9pko9vj3) (version source revid:marko.makela@oracle.com-20100621094008-o9fa153s3f09merw) (pib:20)
[12 Aug 2010 19:29] Paul Dubois
Noted in 5.5.6 changelog.

A single-table DELETE ordered by a column that had a hash-type index 
could raise an assertion or cause a server crash.