# At a local mysql-5.1 repository of davi
2664 Davi Arnaut 2008-06-16
Bug#21704: Renaming column does not update FK definition
The problem was that renaming columns that appear in a foreign
key definition does not cause the definition to be updated to
the new column name. This occurred because the server was not
notifying the storage engine of a possible incompatible change
in column names.
The solution is to iterate over the table fields and check
if any of the columns were renamed. If a column was renamed,
inform that it's not a data compatible change.
It's important to note that this modification will cause a
full table copy to take place when renaming columns on a InnoDB
table.
modified:
mysql-test/include/mix1.inc
mysql-test/r/innodb_mysql.result
storage/innobase/handler/ha_innodb.cc
per-file messages:
mysql-test/include/mix1.inc
Add test case for Bug#21704
mysql-test/r/innodb_mysql.result
Add test case result for Bug#21704
storage/innobase/handler/ha_innodb.cc
Iterate over the table fields checking if a column was renamed.
=== modified file 'mysql-test/include/mix1.inc'
--- a/mysql-test/include/mix1.inc 2008-05-20 07:38:17 +0000
+++ b/mysql-test/include/mix1.inc 2008-06-16 14:40:45 +0000
@@ -1453,4 +1453,33 @@ ALTER TABLE t1 CHANGE id id2 INT;
DROP TABLE t2;
DROP TABLE t1;
+#
+# Bug#21704: Renaming column does not update FK definition.
+#
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+--enable_warnings
+
+CREATE TABLE t1(id INT PRIMARY KEY NOT NULL)
+ ENGINE=innodb;
+
+CREATE TABLE t2(
+ t1_id INT PRIMARY KEY,
+ CONSTRAINT fk1 FOREIGN KEY (t1_id) REFERENCES t1(id))
+ ENGINE=innodb;
+
+--echo
+
+--disable_result_log
+--error ER_ERROR_ON_RENAME
+ALTER TABLE t1 CHANGE id id2 INT NOT NULL;
+--enable_result_log
+
+--echo
+
+DROP TABLE t2;
+DROP TABLE t1;
+
--echo End of 5.1 tests
=== modified file 'mysql-test/r/innodb_mysql.result'
--- a/mysql-test/r/innodb_mysql.result 2008-05-07 05:58:21 +0000
+++ b/mysql-test/r/innodb_mysql.result 2008-06-16 14:40:45 +0000
@@ -1653,6 +1653,19 @@ ALTER TABLE t1 CHANGE id id2 INT;
DROP TABLE t2;
DROP TABLE t1;
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+CREATE TABLE t1(id INT PRIMARY KEY NOT NULL)
+ENGINE=innodb;
+CREATE TABLE t2(
+t1_id INT PRIMARY KEY,
+CONSTRAINT fk1 FOREIGN KEY (t1_id) REFERENCES t1(id))
+ENGINE=innodb;
+
+ALTER TABLE t1 CHANGE id id2 INT NOT NULL;
+
+DROP TABLE t2;
+DROP TABLE t1;
End of 5.1 tests
drop table if exists t1, t2, t3;
create table t1(a int);
=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc 2008-05-14 08:45:32 +0000
+++ b/storage/innobase/handler/ha_innodb.cc 2008-06-16 14:40:45 +0000
@@ -7943,6 +7943,19 @@ bool ha_innobase::check_if_incompatible_
return COMPATIBLE_DATA_NO;
}
+ /* Check that columns were not renamed, because there is no
+ mechanism for updating column names in the InnoDB data
+ dictionary (and in InnoDB foreign key definitions) when
+ column names are updated in the MySQL data dictionary. */
+ for (uint i= 0; i < table->s->fields; i++) {
+ Field *field= table->field[i];
+
+ if (field->flags & FIELD_IS_RENAMED) {
+
+ return COMPATIBLE_DATA_NO;
+ }
+ }
+
return COMPATIBLE_DATA_YES;
}
| Thread |
|---|
| • bzr commit into mysql-5.1 branch (davi:2664) Bug#21704 | Davi Arnaut | 16 Jun |