Bug #32705 myisam corruption: Key in wrong position at page 1024 with ucs2_bin
Submitted: 26 Nov 2007 5:57 Modified: 15 Apr 2008 2:13
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S1 (Critical)
Version:5.1.23, 5.0.50, 6.0.3 OS:Any
Assigned to: Ingo Strüwing CPU Architecture:Any
Tags: Contribution, corruption, myisam, ucs2, ucs2_bin

[26 Nov 2007 5:57] Shane Bester
Description:
mysql> drop table if exists `t0`;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> create table `t0` (`c1` char(255) character set ucs2 collate ucs2_bin not null,key(`c1`)) engine=myisam;
Query OK, 0 rows affected (0.05 sec)

mysql> insert into `t0` values ('marshall\'s');
Query OK, 1 row affected (0.08 sec)

mysql> insert into `t0` values ('marsh');
Query OK, 1 row affected (0.00 sec)

mysql> check table `t0` extended;
+---------+-------+----------+------------------------------------+
| Table   | Op    | Msg_type | Msg_text                           |
+---------+-------+----------+------------------------------------+
| test.t0 | check | error    | Key in wrong position at page 1024 |
| test.t0 | check | error    | Corrupt                            |
+---------+-------+----------+------------------------------------+
2 rows in set (0.05 sec)

How to repeat:
drop table if exists `t0`;
create table `t0` (`c1` char(255) character set ucs2 collate ucs2_bin not null,key(`c1`)) engine=myisam;
insert into `t0` values ('marshall\'s');
insert into `t0` values ('marsh');
check table `t0` extended;
[28 Nov 2007 9:42] Lu Jingdong
I did some order tests and got wrong results. I think the order of the key is wrong.

mysql> drop table if exists t;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> create table t (c1 char(100) character set ucs2 collate ucs2_bin not null,key(c1))
    -> engine=myisam;
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t values ('marshall\'s');
Query OK, 1 row affected (0.01 sec)

mysql> insert into t values ('marsh');
Query OK, 1 row affected (0.00 sec)

mysql> select * from t;
+------------+
| c1         |
+------------+
| marshall's |
| marsh      |
+------------+
2 rows in set (0.00 sec)

mysql> select * from t order by c1;
+------------+
| c1         |
+------------+
| marshall's |
| marsh      |
+------------+
2 rows in set (0.00 sec)

mysql> select * from t order by c1 desc;
+------------+
| c1         |
+------------+
| marsh      |
| marshall's |
+------------+
2 rows in set (0.00 sec)
[3 Dec 2007 13:48] Sergei Golubchik
patch: http://lists.mysql.com/internals/35191
[18 Dec 2007 11:30] 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/40128

ChangeSet@1.2579, 2007-12-18 12:29:50+01:00, istruewing@stella.local +3 -0
  Bug#32705 - myisam corruption: Key in wrong position
              at page 1024 with ucs2_bin
  
  Inserting strings with a common prefix into a table with
  characterset UCS2 corrupted the table.
  
  An efficient search method was used, which compares end space
  with ASCII blank. This doesn't work for character sets like UCS2,
  which do not encode blank like ASCII does.
  
  Use the less efficient search method _mi_seq_search()
  for charsets with mbminlen > 1.
[11 Jan 2008 6:48] Alexander Barkov
The patch is ok to push
[16 Jan 2008 10:48] 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/41030

ChangeSet@1.2580, 2008-01-16 11:48:04+01:00, istruewing@stella.local +4 -0
  Bug#32705 - myisam corruption: Key in wrong position
              at page 1024 with ucs2_bin
  Post-pushbuild fix.
  Moved test from myisam.test to ctype_ucs2_def.test.
  UCS2 is not always available.
[16 Jan 2008 14: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/41033

ChangeSet@1.2654, 2008-01-16 15:38:40+01:00, istruewing@stella.local +1 -0
  Bug#32705 - myisam corruption: Key in wrong position
              at page 1024 with ucs2_bin
  Post merge fix
[17 Jan 2008 9:01] Ingo Strüwing
Queued to 6.0-engines, 5.1-engines, 5.0-engines
[12 Mar 2008 14:53] Shane Bester
why still 'patch queued' ?
[12 Mar 2008 15:15] Ingo Strüwing
Because it is still hanging in the engines trees. We had our merge ticket twice, but lost it due to non-trivial problems in the trees.
[27 Mar 2008 11:20] Bugs System
Pushed into 5.0.60
[27 Mar 2008 11:21] Bugs System
Pushed into 5.1.24-rc
[27 Mar 2008 17:53] Bugs System
Pushed into 6.0.5-alpha
[31 Mar 2008 19:24] Jon Stephens
Pushed into 5.1.23-ndb-6.3.11.
[15 Apr 2008 2:02] Paul Dubois
Noted in 5.0.60, 5.1.24, 6.0.5 changelogs.

Inserting strings with a common prefix into a table that used the
ucs2 character set corrupted the table.