Bug #41574 REPAIR TABLE: crashes for compressed tables
Submitted: 18 Dec 2008 2:05 Modified: 11 Feb 2009 3:42
Reporter: Paul DuBois Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S3 (Non-critical)
Version:5.1,6.0 OS:Any
Assigned to: Satya B CPU Architecture:Any
Tags: regression

[18 Dec 2008 2:05] Paul DuBois
Description:
REPAIR TABLE for a compressed MyISAM table produces the following result in MySQL 4.1 and 5.0:

mysql> repair table t;
+--------+--------+----------+-----------------------------+
| Table  | Op     | Msg_type | Msg_text                    |
+--------+--------+----------+-----------------------------+
| test.t | repair | error    | Table 'test.t' is read only | 
+--------+--------+----------+-----------------------------+
1 row in set, 1 warning (0.00 sec)

In MySQL 5.1 and 6.0, the server crashes:

mysql> repair table t;
ERROR 2013 (HY000): Lost connection to MySQL server during query

So this is a regression. Maybe REPAIR TABLE no longer checks whether the table is compressed?

Note that I am not using the USE_FRM option. (The manual says do not use USE_FRM with compressed tables.)

How to repeat:
Create a MyISAM table:

drop table t;
create table t (i int not null) engine myisam;
flush tables;

Compress the table:

% bin/myisampack data/test/t
Compressing data/test/t.MYD: (0 records)
- Calculating statistics
- Compressing file
Empty file saved in compressed format

Run REPAIR TABLE:

repair table t;

Crash!
[18 Dec 2008 4:51] Valeriy Kravchuk
Thank you for a bug report. Verified with recent 5.1 from bzr:

openxs@suse:/home2/openxs/dbs/5.1> bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.31-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create table tc (i int not null) engine=MyISAM;
Query OK, 0 rows affected (0.09 sec)

mysql> flush tables;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
openxs@suse:/home2/openxs/dbs/5.1> bin/myisampack var/test/tc
Compressing var/test/tc.MYD: (0 records)
- Calculating statistics
- Compressing file
Empty file saved in compressed format
openxs@suse:/home2/openxs/dbs/5.1> bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.31-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> repair table tc;
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> 081121 10:04:50 mysqld_safe Number of processes running now: 0
081121 10:04:50 mysqld_safe mysqld restarted

No reasonable stack trace generated.
[18 Dec 2008 4:54] Valeriy Kravchuk
Sorry, stack trace is:

... (my_print_stacktrace+0x29)[0x86ac078]
... (handle_segfault+0x253)[0x8288d69]
[0xffffe420]
/lib/tls/libc.so.6(abort+0x1a5)[0x400e6b75]
/lib/tls/libc.so.6(__assert_fail+0x103)[0x400de903]
... (_ZN16Diagnostics_area14set_eof_statusEP3THD+0x39)[0x826efcb]
... (_Z6my_eofP3THD+0x1d)[0x81b524d]
... [0x83d51bc]
... (_Z18mysql_repair_tableP3THDP10TABLE_LISTP15st_ha_check_opt+0xca)[0x83d563c]
... (_Z21mysql_execute_commandP3THD+0x2310)[0x829a9a2]
... (_Z11mysql_parseP3THDPKcjPS2_+0x1d5)[0x82a2915]
... (_Z16dispatch_command19enum_server_commandP3THDPcj+0x9c9)[0x8296e43]
... (_Z10do_commandP3THD+0x254)[0x82961ec]
... (handle_one_connection+0x123)[0x82947cb]
/lib/tls/libpthread.so.0[0x40031aa7]
/lib/tls/libc.so.6(__clone+0x5e)[0x40177c2e]
[18 Dec 2008 4:56] Valeriy Kravchuk
Same crash with latest 6.0.9 from bzr.
[21 Jan 2009 11:21] 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/63695

2749 Satya B	2009-01-21
      Fix for BUG#41574 REPAIR TABLE: crashes for compressed tables
      
      REPAIR TABLE after myisam compression on myisam tables crashes the server
      
      After the table is compressed , it becomes read-only. When opening the tables
      for repair,the server detects the table as read-only but it doesn't send the
      error message properly.
[21 Jan 2009 11:48] Satya B
I am about to submit a better patch and found that someone already did it for me. The earlier patch is incorrect.

   if ((table->table->db_stat & HA_READ_ONLY) && open_for_modify)
    {
        .....
        .....
        ......
        if (protocol->write())
        goto err;
      * thd->main_da.reset_diagnostics_area(); *
        continue;
    }

in mysql_admin_table at sql_table.cc

The line in between the two '*' is the fix. However the tests do not exist, I will submit a new patch only with test cases.
[21 Jan 2009 11:56] 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/63698

2749 Satya B	2009-01-21
      TestCase for BUG#41574 - REPAIR TABLE: crashes for compressed tables
      
      Adding Testcases only as the bug is fixed already
[21 Jan 2009 12:18] Sergey Vojtovich
This was fixed by patch for BUG#40949.
[21 Jan 2009 12:54] 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/63708

2749 Satya B	2009-01-21
      TestCase for BUG#41574 - REPAIR TABLE: crashes for compressed tables
      
      Adding two testcases as the bug is already fixed
      
      TestCase-1 Test repair table after compression without 'OPTIMIZE TABLE'
      TestCase-2 Test repair table after compression with 'OPTIMIZE TABLE'
[22 Jan 2009 5:55] 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/63789

2750 Satya B	2009-01-22
      TestCase for BUG#41574 - REPAIR TABLE: crashes for compressed tables
      
      Extending the existing testcase written for BUG#40949 to verify
      repair table operation for compressed tables
[3 Feb 2009 9:41] Bugs System
Pushed into 5.1.32 (revid:joro@sun.com-20090203090549-gos3v4320vimrzg6) (version source revid:horst@mysql.com-20090123182108-2efo5zwexcrf0h3o) (merge vers: 5.1.32) (pib:6)
[4 Feb 2009 11:16] Bugs System
Pushed into 6.0.10-alpha (revid:kostja@sun.com-20090204104420-mw1i2u9lum4bxjo6) (version source revid:aelkin@mysql.com-20090123192116-kg0rza3xkvq3nc94) (merge vers: 6.0.10-alpha) (pib:6)
[11 Feb 2009 3:42] Paul DuBois
Noted in 5.1.32, 6.0.10 changelogs.

REPAIR TABLE crashed for compressed MyISAM tables.
[17 Feb 2009 15:00] Bugs System
Pushed into 5.1.32-ndb-6.3.23 (revid:tomas.ulin@sun.com-20090217131017-6u8qz1edkjfiobef) (version source revid:tomas.ulin@sun.com-20090203133556-9rclp06ol19bmzs4) (merge vers: 5.1.32-ndb-6.3.22) (pib:6)
[17 Feb 2009 16:48] Bugs System
Pushed into 5.1.32-ndb-6.4.3 (revid:tomas.ulin@sun.com-20090217134419-5ha6xg4dpedrbmau) (version source revid:tomas.ulin@sun.com-20090203133556-9rclp06ol19bmzs4) (merge vers: 5.1.32-ndb-6.3.22) (pib:6)
[17 Feb 2009 18:24] Bugs System
Pushed into 5.1.32-ndb-6.2.17 (revid:tomas.ulin@sun.com-20090217134216-5699eq74ws4oxa0j) (version source revid:tomas.ulin@sun.com-20090202111723-1zzwax187rtls913) (merge vers: 5.1.32-ndb-6.2.17) (pib:6)