Bug #11558 MyISAM table get corrupted when inserting utf8 data
Submitted: 24 Jun 2005 23:51 Modified: 9 Aug 2005 15:32
Reporter: Shuichi Tamagawa Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S1 (Critical)
Version:5.0.7 / 4.1.12 OS:Windows (Windows XP / Linux)
Assigned to: Ingo Strüwing CPU Architecture:Any

[24 Jun 2005 23:51] Shuichi Tamagawa
Description:
# This is originally repored by Mr. Masahiro Tomita 

MyISAM table get corrupted when inserting utf8 data

How to repeat:
Repeatable on both 4.1.12 and  5.0.7.

[4.1.12]
mysql> show create table example\G
*************************** 1. row ***************************
       Table: example
Create Table: CREATE TABLE `example` (
  `id` int(11) NOT NULL default '0',
  `subid` int(11) NOT NULL auto_increment,
  `str` varchar(255) default NULL,
  UNIQUE KEY `id` (`id`,`subid`),
  KEY `str` (`str`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.02 sec)

mysql> insert into example values (0,0,0xE988B4E9B9BFE88090E4B985);
Query OK, 1 row affected (0.00 sec)

mysql> insert into example values (1,0,0xE988B4E9B9BF2E686F6765);
ERROR 1032 (HY000): Can't find record in 'example'
mysql> check table example;
+--------------+-------+----------+---------------------------------------------------------------+
| Table        | Op    | Msg_type | Msg_text                                                      |
+--------------+-------+----------+---------------------------------------------------------------+
| test.example | check | warning  | Table is marked as crashed                                    |
| test.example | check | error    | Found key at page 1024 that points to record outside datafile |
| test.example | check | error    | Corrupt                                                       |
+--------------+-------+----------+---------------------------------------------------------------+
3 rows in set (0.02 sec)

mysql> repair table example;
+--------------+--------+----------+----------+
| Table        | Op     | Msg_type | Msg_text |
+--------------+--------+----------+----------+
| test.example | repair | status   | OK       |
+--------------+--------+----------+----------+
1 row in set (0.02 sec)

[5.0.7]
mysql> show create table example\G
*************************** 1. row ***************************
       Table: example
Create Table: CREATE TABLE `example` (
  `id` int(11) NOT NULL default '0',
  `subid` int(11) NOT NULL auto_increment,
  `str` varchar(255) default NULL,
  UNIQUE KEY `id` (`id`,`subid`),
  KEY `str` (`str`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

mysql> insert into example values (0,0,0xE988B4E9B9BFE88090E4B985);
Query OK, 1 row affected (0.00 sec)

mysql> insert into example values (1,0,0xE988B4E9B9BF2E686F6765);
ERROR 126 (HY000): Incorrect key file for table '.\test\example.MYI'; try to repair it
mysql> check table example;
+--------------+-------+----------+---------------------------------------------------------------+
| Table        | Op    | Msg_type | Msg_text                                                      |
+--------------+-------+----------+---------------------------------------------------------------+
| test.example | check | warning  | Table is marked as crashed                                    |
| test.example | check | error    | Found key at page 1024 that points to record outside datafile |
| test.example | check | error    | Corrupt                                                       |
+--------------+-------+----------+---------------------------------------------------------------+
3 rows in set (0.02 sec)

mysql> repair table example;
+--------------+--------+----------+----------+
| Table        | Op     | Msg_type | Msg_text |
+--------------+--------+----------+----------+
| test.example | repair | status   | OK       |
+--------------+--------+----------+----------+
1 row in set (0.03 sec)

Suggested fix:
N/A
[25 Jun 2005 0:14] MySQL Verification Team
mysql> insert into example values (1,0,0xE988B4E9B9BF2E686F6765);
ERROR 126 (HY000): Incorrect key file for table './test/example.MYI'; try to repair it
mysql> check table example\G
*************************** 1. row ***************************
   Table: test.example
      Op: check
Msg_type: warning
Msg_text: Table is marked as crashed
*************************** 2. row ***************************
   Table: test.example
      Op: check
Msg_type: error
Msg_text: Found key at page 1024 that points to record outside datafile
*************************** 3. row ***************************
   Table: test.example
      Op: check
Msg_type: error
Msg_text: Corrupt
3 rows in set (0.01 sec)

mysql> select version();
+------------------+
| version()        |
+------------------+
| 5.0.9-beta-debug |
+------------------+
1 row in set (0.02 sec)

mysql> 

Thank you for the bug report.
[9 Aug 2005 15:32] Ingo Strüwing
I cannot repeat this on 4.1.14 and 5.1.12. I am positive that it has been fixed already. The changelogs tell of similar fixed bugs.