#At file:///home/dlenev/src/bzr/mysql-6.1-mil13/ based on revid:dlenev@stripped
2750 Dmitry Lenev 2009-07-23
Milestone 13 "DDL checks and changes: ALTER, CREATE INDEX, DROP INDEX words".
Work in progress. Improved test coverage for one of failure scenarios.
modified:
mysql-test/r/foreign_key_all_engines_3.result
mysql-test/t/foreign_key_all_engines_3.test
sql/sql_table.cc
=== modified file 'mysql-test/r/foreign_key_all_engines_3.result'
--- a/mysql-test/r/foreign_key_all_engines_3.result 2009-07-06 10:18:25 +0000
+++ b/mysql-test/r/foreign_key_all_engines_3.result 2009-07-23 14:36:14 +0000
@@ -251,9 +251,41 @@ ERROR 42000: Foreign key error: Constrai
create table t5 (pk int primary key, fk int constraint c2 references t5 (pk));
drop table t5;
create table t5 (pk int primary key, fk int constraint c3 references t5 (pk));
+drop table t5;
+# Now let us check what happens when attempt to replace old version of
+# table being altered with its new version fails (for "fast" ALTER).
+insert into t1 values (1);
+insert into t3 values (1);
+set foreign_key_checks= 0;
+set debug= "d,fast_or_online_alter_table_rename_table_fail";
+alter table t4 drop constraint c1,
+add constraint c2 foreign key (fk2) references t3 (pk),
+add constraint c3 foreign key (fk3) references t1 (pk);
+ERROR HY000: Unknown error
+set debug= @old_debug;
+set foreign_key_checks= 1;
+# Again let us check that .FRMs are not changed, and constraint
+# names were not touched.
+show create table t4;
+Table Create Table
+t4 CREATE TABLE `t4` (
+ `fk1` int(11) DEFAULT NULL CONSTRAINT `c1` REFERENCES `t2` (`pk`),
+ `fk2` int(11) DEFAULT NULL,
+ `fk3` int(11) DEFAULT NULL,
+ KEY `fk2` (`fk2`),
+ KEY `fk3` (`fk3`),
+ KEY `c1` (`fk1`)
+) ENGINE=<engine_type> DEFAULT CHARSET=latin1
+delete from t1 where pk = 1;
+delete from t2 where pk = 1;
+ERROR 23000: Foreign key error: constraint 'c1': cannot change because foreign key refers to value '1'
+delete from t3 where pk = 1;
+create table t5 (pk int primary key, fk int constraint c1 references t5 (pk));
+ERROR 42000: Foreign key error: Constraint 'c1': Duplicate constraint name
+create table t5 (pk int primary key, fk int constraint c2 references t5 (pk));
+drop table t5;
+create table t5 (pk int primary key, fk int constraint c3 references t5 (pk));
drop tables t1, t2, t3, t4, t5;
-# Re test for scenario when attempt to replace old version of table with
-# its new version fails see QQ in mysql_fast_or_online_alter_table().
# Finally let us tests how ALTER TABLE failures are handled when it
# is executed under LOCK TABLES.
#
=== modified file 'mysql-test/t/foreign_key_all_engines_3.test'
--- a/mysql-test/t/foreign_key_all_engines_3.test 2009-07-06 10:18:25 +0000
+++ b/mysql-test/t/foreign_key_all_engines_3.test 2009-07-23 14:36:14 +0000
@@ -228,10 +228,34 @@ create table t5 (pk int primary key, fk
create table t5 (pk int primary key, fk int constraint c2 references t5 (pk));
drop table t5;
create table t5 (pk int primary key, fk int constraint c3 references t5 (pk));
-drop tables t1, t2, t3, t4, t5;
+drop table t5;
---echo # Re test for scenario when attempt to replace old version of table with
---echo # its new version fails see QQ in mysql_fast_or_online_alter_table().
+--echo # Now let us check what happens when attempt to replace old version of
+--echo # table being altered with its new version fails (for "fast" ALTER).
+insert into t1 values (1);
+insert into t3 values (1);
+set foreign_key_checks= 0;
+set debug= "d,fast_or_online_alter_table_rename_table_fail";
+--error ER_UNKNOWN_ERROR
+alter table t4 drop constraint c1,
+ add constraint c2 foreign key (fk2) references t3 (pk),
+ add constraint c3 foreign key (fk3) references t1 (pk);
+set debug= @old_debug;
+set foreign_key_checks= 1;
+--echo # Again let us check that .FRMs are not changed, and constraint
+--echo # names were not touched.
+--replace_result $engine_type <engine_type>
+show create table t4;
+delete from t1 where pk = 1;
+--error ER_FK_CHILD_VALUE_EXISTS
+delete from t2 where pk = 1;
+delete from t3 where pk = 1;
+--error ER_FK_CONSTRAINT_NAME_DUPLICATE
+create table t5 (pk int primary key, fk int constraint c1 references t5 (pk));
+create table t5 (pk int primary key, fk int constraint c2 references t5 (pk));
+drop table t5;
+create table t5 (pk int primary key, fk int constraint c3 references t5 (pk));
+drop tables t1, t2, t3, t4, t5;
--echo # Finally let us tests how ALTER TABLE failures are handled when it
--echo # is executed under LOCK TABLES.
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2009-07-23 13:53:40 +0000
+++ b/sql/sql_table.cc 2009-07-23 14:36:14 +0000
@@ -8144,7 +8144,7 @@ mysql_fast_or_online_alter_table(THD *th
{
TABLE *table= table_list->table;
bool is_online_alter= table->file->ha_table_flags() & HA_ONLINE_ALTER;
- int error;
+ int error= 0;
DBUG_ENTER("mysql_fast_or_online_alter_table");
@@ -8195,11 +8195,18 @@ mysql_fast_or_online_alter_table(THD *th
Let's rename it to the original table name.
*/
pthread_mutex_lock(&LOCK_open);
- error= mysql_rename_table(NULL,
- altered_table->s->db.str,
- altered_table->s->table_name.str,
- table_list->db, table_list->table_name,
- FN_FROM_IS_TMP);
+
+ DBUG_EXECUTE_IF("fast_or_online_alter_table_rename_table_fail",
+ { my_error(ER_UNKNOWN_ERROR, MYF(0)); error= 1; });
+
+ if (! error)
+ {
+ error= mysql_rename_table(NULL,
+ altered_table->s->db.str,
+ altered_table->s->table_name.str,
+ table_list->db, table_list->table_name,
+ FN_FROM_IS_TMP);
+ }
pthread_mutex_unlock(&LOCK_open);
if (! error)
Attachment: [text/bzr-bundle] bzr/dlenev@mysql.com-20090723143614-h2djcxs76ij3jr33.bundle
| Thread |
|---|
| • bzr commit into mysql-6.1-fk branch (dlenev:2750) | Dmitry Lenev | 23 Jul |