Bug #27123 partition + on duplicate key update + varchar = Can't find record in table
Submitted: 14 Mar 2007 9:49 Modified: 9 May 2007 6:05
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Partitions Severity:S2 (Serious)
Version:5.1.17BK OS:Linux (suse 9.3 x86)
Assigned to: Alexey Botchkov CPU Architecture:Any
Tags: partition

[14 Mar 2007 9:49] Shane Bester
Description:
when you have a primary key that is a varchar, and the table is partitioned on that column, 'on duplicate key update' doesn't work:

changing varchar(255) to be char(255) causes the problem to go away.

mysql> drop table if exists `t1`;
Query OK, 0 rows affected (0.00 sec)

mysql> create table `t1` (`c1` varchar(255),`c2` tinyint,primary key(`c1`))engine=myisam partition by key (`c1`) partitions 10 ;
Query OK, 0 rows affected (0.72 sec)

mysql> insert into `t1` values ('aaa','1') on duplicate key update `c2` = `c2` + 1;
Query OK, 1 row affected (0.00 sec)

mysql> insert into `t1` values ('aaa','1') on duplicate key update `c2` = `c2` + 1;
ERROR 1032 (HY000): Can't find record in 't1'
mysql> select * from `t1`;
+-----+------+
| c1  | c2   |
+-----+------+
| aaa |    1 |
+-----+------+
1 row in set (0.00 sec)

How to repeat:
drop table if exists `t1`;
create table `t1` (`c1` varchar(255),`c2` tinyint,primary key(`c1`))engine=myisam partition by key (`c1`) partitions 10 ; 
insert into `t1` values ('aaa','1') on duplicate key update `c2` = `c2` + 1; 
insert into `t1` values ('aaa','1') on duplicate key update `c2` = `c2` + 1; 
select * from `t1`;

Suggested fix:
.
[25 Mar 2007 14:25] 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/22891

ChangeSet@1.2501, 2007-03-25 19:25:51+05:00, holyfoot@mysql.com +3 -0
  Bug #27123 partition + on duplicate key update + varchar = Can't find record in <table> 
     key_restore function didn't work as it was described in
     the description in the case of VARCHAR or BLOB fields, it
     stored the restored key in field->ptr instead of to_record.
     That produced wrong key so searching failed.
[4 Apr 2007 14:42] 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/23809

ChangeSet@1.2558, 2007-04-04 18:42:12+05:00, holyfoot@mysql.com +6 -0
  Bug #27123 (partition + on duplicate key update + varchar = Can't find record
  in table)
  
  key_restore function didn't work as it was intended in the case
  of VARCHAR and BLOB fields, as it stored the restored key in field->ptr
  instead of to_record.
  That produced wrong key so search returned wrong result.
[19 Apr 2007 17:44] 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/24926

ChangeSet@1.2590, 2007-04-19 21:43:42+05:00, holyfoot@mysql.com +6 -0
  Bug #27123 (partition + on duplicate key update + varchar = Can't find
  record in table)
  
  key_restore function didn't work as intended in the case of
  VARCHAR or BLOB fields, stored the restored key in field->ptr instead
  of to_record.
  That produced the wrong key so search returned wrong result
[7 May 2007 18:14] Bugs System
Pushed into 5.1.18-beta
[9 May 2007 6:05] Jon Stephens
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html

Documented fix in 5.1.18 changelog.