From: Pekka Nousiainen Date: September 22 2012 10:12am Subject: bzr push into mysql-5.5-cluster-7.3-fk branch (pekka.nousiainen:3918 to 3919) WL#6244 List-Archive: http://lists.mysql.com/commits/144862 Message-Id: <20120922101257.19942.17410.3919@cuda> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3919 Pekka Nousiainen 2012-09-22 wl#6244 errcode5.diff column compatibility (from Jul 2 patch) modified: mysql-test/suite/ndb/r/ndb_fk_bugs.result mysql-test/suite/ndb/t/ndb_fk_bugs.test sql/ha_ndb_ddl_fk.cc 3918 Pekka Nousiainen 2012-09-20 wl#6244 errcode4.diff bug#14124623 test case from bug report modified: mysql-test/suite/ndb/r/ndb_fk_bugs.result mysql-test/suite/ndb/t/ndb_fk_bugs.test === modified file 'mysql-test/suite/ndb/r/ndb_fk_bugs.result' --- a/mysql-test/suite/ndb/r/ndb_fk_bugs.result 2012-09-20 08:36:30 +0000 +++ b/mysql-test/suite/ndb/r/ndb_fk_bugs.result 2012-09-22 10:10:42 +0000 @@ -90,3 +90,36 @@ Warning 1296 Got error 21026 'Create for Error 1005 Can't create table 'test.languages' (errno: 150) CREATE TABLE languages (id INT NOT NULL PRIMARY KEY) engine=ndb; drop table languages, towns, counties; +"# test: child vs parent column types" +create table t1 ( +a int not null, +b int not null, +primary key using hash (a), +unique key using hash (b) +) engine ndb; +create table t2 ( +a int not null, +b char(20) not null, +primary key using hash (a), +key (b), +constraint fk1 foreign key (b) references t1 (b) +) engine ndb; +ERROR HY000: Can't create table 'test.t2' (errno: 150) +show warnings; +Level Code Message +Warning 1215 Parent column t1.b is incompatible with child column t2.b in NDB +Error 1005 Can't create table 'test.t2' (errno: 150) +create table t2 ( +a int not null, +b char(10) not null, +primary key using hash (a), +key (b) +) engine ndb; +alter online table t2 +add constraint fk1 foreign key (b) references t1 (b); +ERROR HY000: Cannot add foreign key constraint +show warnings; +Level Code Message +Warning 1215 Parent column t1.b is incompatible with child column t2.b in NDB +Error 150 Cannot add foreign key constraint +drop table t2, t1; === modified file 'mysql-test/suite/ndb/t/ndb_fk_bugs.test' --- a/mysql-test/suite/ndb/t/ndb_fk_bugs.test 2012-09-20 08:36:30 +0000 +++ b/mysql-test/suite/ndb/t/ndb_fk_bugs.test 2012-09-22 10:10:42 +0000 @@ -110,3 +110,36 @@ show warnings; CREATE TABLE languages (id INT NOT NULL PRIMARY KEY) engine=ndb; drop table languages, towns, counties; + +--echo "# test: child vs parent column types" + +create table t1 ( + a int not null, + b int not null, + primary key using hash (a), + unique key using hash (b) +) engine ndb; + +--error ER_CANT_CREATE_TABLE +create table t2 ( + a int not null, + b char(20) not null, + primary key using hash (a), + key (b), + constraint fk1 foreign key (b) references t1 (b) +) engine ndb; +show warnings; + +create table t2 ( + a int not null, + b char(10) not null, + primary key using hash (a), + key (b) +) engine ndb; + +--error 150 +alter online table t2 + add constraint fk1 foreign key (b) references t1 (b); +show warnings; + +drop table t2, t1; === modified file 'sql/ha_ndb_ddl_fk.cc' --- a/sql/ha_ndb_ddl_fk.cc 2012-09-18 13:15:29 +0000 +++ b/sql/ha_ndb_ddl_fk.cc 2012-09-22 10:10:42 +0000 @@ -361,6 +361,27 @@ ha_ndbcluster::create_fks(THD *thd, Ndb DBUG_RETURN(err_default); } + { + /** + * Check that columns match...this happens to be same + * condition as the one for SPJ... + */ + for (unsigned i = 0; parentcols[i] != 0; i++) + { + if (parentcols[i]->isBindable(* childcols[i]) == -1) + { + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_CANNOT_ADD_FOREIGN, + "Parent column %s.%s is incompatible with child column %s.%s in NDB", + parent_tab.get_table()->getName(), + parentcols[i]->getName(), + child_tab.get_table()->getName(), + childcols[i]->getName()); + DBUG_RETURN(err_default); + } + } + } + NdbDictionary::ForeignKey ndbfk; if (!isnull(fk->name)) { No bundle (reason: useless for push emails).