diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index 2bdec5125dd..e0b477ab543 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -2475,3 +2475,11 @@ SELECT GRADE FROM t1 WHERE GRADE= 151; GRADE 151 DROP TABLE t1; +create table t1 (f1 varchar(10), f2 varchar(10), primary key (f1,f2)) engine=innodb; +create table t2 (f3 varchar(10), f4 varchar(10), key (f4)) engine=innodb; +insert into t2 values ('aa','cc'); +insert into t1 values ('aa','bb'),('aa','cc'); +delete t1 from t1,t2 where f1=f3 and f4='cc'; +select * from t1; +f1 f2 +drop table t1,t2; diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index 05f47f36e42..0ec7faa8ade 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -1394,3 +1394,13 @@ SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300; SELECT GRADE FROM t1 WHERE GRADE= 151; DROP TABLE t1; +# +# Bug #12340 multitable delete deletes only one record +# +create table t1 (f1 varchar(10), f2 varchar(10), primary key (f1,f2)) engine=innodb; +create table t2 (f3 varchar(10), f4 varchar(10), key (f4)) engine=innodb; +insert into t2 values ('aa','cc'); +insert into t1 values ('aa','bb'),('aa','cc'); +delete t1 from t1,t2 where f1=f3 and f4='cc'; +select * from t1; +drop table t1,t2; diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index d98222975c5..026bc0da13d 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -6852,8 +6852,8 @@ ha_innobase::cmp_ref( return(result); } - ref1 += key_part->length; - ref2 += key_part->length; + ref1 += key_part->store_length; + ref2 += key_part->store_length; } return(0);