Bug #42074 concurrent optimize table and alter table = Assertion failed: thd->is_error()
Submitted: 13 Jan 2009 9:56 Modified: 7 Mar 2010 12:56
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S1 (Critical)
Version:5.1.30-debug, 5.1.31-debug, 6.0.10-debug OS:Any
Assigned to: Jon Olav Hauglid CPU Architecture:Any
Tags: assertion, regression

[13 Jan 2009 9:56] Shane Bester
Description:
when running a concurrent mix of the following statements, an assertion trips.

optimize table `t1`;
alter table `t1` engine=innodb;
alter table `t1` engine=memory;

5.0.x is not affected, hence a regression.

Version: '5.1.30-community-debug'  socket: ''  port: 3306  MySQL Community Server - Debug (GPL)
Assertion failed: thd->is_error(), file .\sql_table.cc, line 4511

mysqld-debug.exe!my_sigabrt_handler()[mysqld.cc:1985]
mysqld-debug.exe!raise()[winsig.c:597]
mysqld-debug.exe!abort()[abort.c:78]
mysqld-debug.exe!_wassert()[assert.c:212]
mysqld-debug.exe!mysql_admin_table()[sql_table.cc:4511]
mysqld-debug.exe!mysql_optimize_table()[sql_table.cc:4652]
mysqld-debug.exe!mysql_execute_command()[sql_parse.cc:2933]
mysqld-debug.exe!mysql_parse()[sql_parse.cc:5791]
mysqld-debug.exe!dispatch_command()[sql_parse.cc:1202]
mysqld-debug.exe!do_command()[sql_parse.cc:857]
mysqld-debug.exe!handle_one_connection()[sql_connect.cc:1115]
mysqld-debug.exe!pthread_start()[my_winthread.c:85]
mysqld-debug.exe!_callthreadstart()[thread.c:295]
mysqld-debug.exe!_threadstart()[thread.c:277]
kernel32.dll!BaseThreadStart()
ariables.
 invalid and cause the dump to abort...
0004C900E8=optimize table `t1`

How to repeat:
see attached .c testcase.
[13 Jan 2009 10:01] MySQL Verification Team
testcase

Attachment: bug42074.c (text/plain), 6.11 KiB.

[22 Aug 2009 9:50] Konstantin Osipov
5.4 regression, please re-triage.
[28 Aug 2009 12:27] Jon Olav Hauglid
This is what causes the assert:
1) mysql_admin_table() calls table->table->file->ha_analyze()
2) ha_heap does not implement analyze() which causes
ha_analyze() to return HA_ADMIN_NOT_IMPLEMENTED (= -1)
3) The return value of -1 triggers "if (result_code) // either mysql_recreate_table or analyze failed"
4) Assert fails because the diagnostics area has not been filled with an error.
[31 Aug 2009 12:49] 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/81997

2804 Jon Olav Hauglid	2009-08-31
      Bug #42074 concurrent optimize table and 
                 alter table = Assertion failed: thd->is_error()
      
      This bug could occur if OPTIMIZE TABLE was started on a InnoDB table
      and the table was altered to different storage engine after OPTIMIZE
      had started. This allowed OPTIMIZE to pass the initial checks for 
      storage engine support, but fail once it reached "recreate+analyze"
      if this operation was not supported by the new storage engine.
      
      If the call to ha_analyze() returned HA_ADMIN_NOT_IMPLEMENTED,
      this would trigger a code path which included an assert checking
      for diagnostics area contents. Since this area had not been filled,
      the assert was triggered.
      
      This patch removes the assertion. The diagnostics area is in this case
      only used to provide more detailed information about why optimize failed.
      The triggered code path sends this information to the client and clears 
      the diagnostic area.
      
      Test case added to innodb_mysql.test.
[15 Sep 2009 19:50] Konstantin Osipov
Approved with a couple of requests over email.
[16 Sep 2009 9:24] 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/83448

2857 Jon Olav Hauglid	2009-09-16
      Bug #42074 concurrent optimize table and 
                 alter table = Assertion failed: thd->is_error()
      
      This assertion could occur if OPTIMIZE TABLE was started on a InnoDB table
      and the table was altered to different storage engine after OPTIMIZE
      had started. This allowed OPTIMIZE to pass the initial checks for 
      storage engine support, but fail once it reached "recreate+analyze"
      if this operation was not supported by the new storage engine.
      The bug had no consequences for non-debug builds of the server.
      
      In detail, the assertion was triggered when ha_analyze() returned 
      HA_ADMIN_NOT_IMPLEMENTED. This led to a code path which included an 
      assert checking for diagnostics area contents. Since this area had 
      not been filled, the assertion was triggered. The diagnostics area 
      is in this case only used to provide more detailed information about 
      why optimize failed. The triggered code path sends this information 
      to the client and clears the diagnostic area.
      
      This patch fixed the problem by adding an error message to the diagnostic 
      area if ha_analyze() fails. This error message contains the error code
      returned by ha_analyze().
      
      Test case added to innodb_mysql_sync.test.
[16 Sep 2009 12:39] 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/83479

2860 Jon Olav Hauglid	2009-09-16
      Bug #42074 concurrent optimize table and 
                 alter table = Assertion failed: thd->is_error()
      
      This assertion could occur if OPTIMIZE TABLE was started on a InnoDB table
      and the table was altered to different storage engine after OPTIMIZE
      had started. This allowed OPTIMIZE to pass the initial checks for 
      storage engine support, but fail once it reached "recreate+analyze"
      if this operation was not supported by the new storage engine.
      The bug had no consequences for non-debug builds of the server.
      
      In detail, the assertion was triggered when ha_analyze() returned 
      HA_ADMIN_NOT_IMPLEMENTED. This led to a code path which included an 
      assert checking for diagnostics area contents. Since this area had 
      not been filled, the assertion was triggered. The diagnostics area 
      is in this case only used to provide more detailed information about 
      why optimize failed. The triggered code path sends this information 
      to the client and clears the diagnostic area.
      
      This patch fixed the problem by adding an error message to the diagnostic 
      area if ha_analyze() fails. This error message contains the error code
      returned by ha_analyze().
      
      Test case added to innodb_mysql_sync.test.
[16 Sep 2009 12:43] Jon Olav Hauglid
Pushed to mysql-6.0-codebase-bugfixing (6.0.14-alpha)
[30 Sep 2009 8:18] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20090929093622-1mooerbh12e97zux) (version source revid:alik@sun.com-20090923103200-kyo2bakdo6tfb2fb) (merge vers: 6.0.14-alpha) (pib:11)
[30 Sep 2009 20:18] Paul DuBois
Noted in 6.0.14 changelog.

An assertion failure could occur if OPTIMIZE TABLE was started on an
InnoDB table and the table was altered to a different storage engine
during the optimization operation. 

Setting report to NDI pending push into 5.4.x.
[9 Dec 2009 8:33] Jon Olav Hauglid
Pushed to mysql-next-4284 (5.6.0-beta).
[16 Feb 2010 16:47] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100216101445-2ofzkh48aq2e0e8o) (version source revid:kostja@sun.com-20091211154405-c9yhiewr9o5d20rq) (merge vers: 6.0.14-alpha) (pib:16)
[16 Feb 2010 16:56] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100216101208-33qkfwdr0tep3pf2) (version source revid:jon.hauglid@sun.com-20091209083229-skmkppsgsi11knkj) (pib:16)
[17 Feb 2010 0:25] Paul DuBois
Setting report to Need Merge pending push of Celosia into release tree.
[6 Mar 2010 11:03] Bugs System
Pushed into 5.5.3-m3 (revid:alik@sun.com-20100306103849-hha31z2enhh7jwt3) (version source revid:vvaintroub@mysql.com-20100216221947-luyhph0txl2c5tc8) (merge vers: 5.5.99-m3) (pib:16)
[7 Mar 2010 12:56] Paul DuBois
Noted in 5.5.3 changelog.