Commit 2a4c1902 authored by Aleksey Midenkov's avatar Aleksey Midenkov

FIXMEs, fixes, tests

- alter fix
- Test definite order fix
parent 4f34732e
...@@ -54,7 +54,7 @@ if ($crash_statement) ...@@ -54,7 +54,7 @@ if ($crash_statement)
--echo # State after crash (before recovery) --echo # State after crash (before recovery)
--list_files_write_file $DATADIR.files.txt $DATADIR/test --list_files_write_file $DATADIR.files.txt $DATADIR/test
--replace_result #p# #P# #sp# #SP# #tmp# #TMP# --replace_result #p# #P# #sp# #SP# #tmp# #TMP#
--replace_regex /sql-exchange.*\./sql-exchange./ /sql-shadow-[0-9a-f]*-/sql-shadow-/ /sql-alter-[0-9a-f]*-/sql-alter-/ /#sql-ib[1-9][0-9]*\.ibd\n// --replace_regex /sql-exchange.*\./sql-exchange./ /sql(f?)-shadow-[0-9a-f]*-/sql\1-shadow-/ /sql-alter-[0-9a-f]*-/sql-alter-/ /#sql-ib[1-9][0-9]*\.ibd\n//
--cat_file $DATADIR.files.txt --cat_file $DATADIR.files.txt
--remove_file $DATADIR.files.txt --remove_file $DATADIR.files.txt
...@@ -68,6 +68,9 @@ if ($crash_statement) ...@@ -68,6 +68,9 @@ if ($crash_statement)
--replace_regex /sql-alter-[0-9a-f]*-/sql-alter-/ /#sql-ib[1-9][0-9]*\.ibd\n// --replace_regex /sql-alter-[0-9a-f]*-/sql-alter-/ /#sql-ib[1-9][0-9]*\.ibd\n//
--cat_file $DATADIR.files.txt --cat_file $DATADIR.files.txt
--remove_file $DATADIR.files.txt --remove_file $DATADIR.files.txt
# TODO: when ALTER crashes it leaves tmp garbage. Should be fixed via DDL log
# (though engine files can left too).
--remove_files_wildcard $DATADIR/test #sql-alter*.*
} }
if (!$crash_statement) if (!$crash_statement)
......
...@@ -306,8 +306,8 @@ set @@debug_dbug= "+d,crash_fk_write_shadow_frm"; ...@@ -306,8 +306,8 @@ set @@debug_dbug= "+d,crash_fk_write_shadow_frm";
drop tables t4, t1, t3, t2; drop tables t4, t1, t3, t2;
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlf-shadow-4-t2.frm #sqlf-shadow-t2.frm
#sqlf-shadow-4-t3.frm #sqlf-shadow-t3.frm
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
...@@ -400,16 +400,16 @@ set @@debug_dbug= "+d,crash_fk_backup_frm"; ...@@ -400,16 +400,16 @@ set @@debug_dbug= "+d,crash_fk_backup_frm";
drop tables t4, t1, t3, t2; drop tables t4, t1, t3, t2;
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlf-shadow-3-t1.frm #sqlf-shadow-t1.frm
#sqlf-shadow-3-t2.frm #sqlf-shadow-t2.frm
#sqlf-shadow-3-t3.frm #sqlf-shadow-t3.frm
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
t1.fbk t1.frm
t2.MYD t2.MYD
t2.MYI t2.MYI
t2.frm t2.fbk
t3.MYD t3.MYD
t3.MYI t3.MYI
t3.fbk t3.fbk
...@@ -495,15 +495,15 @@ set @@debug_dbug= "+d,crash_fk_install_shadow_frm"; ...@@ -495,15 +495,15 @@ set @@debug_dbug= "+d,crash_fk_install_shadow_frm";
drop tables t4, t1, t3, t2; drop tables t4, t1, t3, t2;
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlf-shadow-3-t2.frm #sqlf-shadow-t1.frm
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
t1.fbk t1.fbk
t1.frm
t2.MYD t2.MYD
t2.MYI t2.MYI
t2.fbk t2.fbk
t2.frm
t3.MYD t3.MYD
t3.MYI t3.MYI
t3.fbk t3.fbk
...@@ -768,8 +768,8 @@ set @@debug_dbug= "+d,crash_fk_write_shadow_frm"; ...@@ -768,8 +768,8 @@ set @@debug_dbug= "+d,crash_fk_write_shadow_frm";
create table t4 (a int primary key, x int references t1(x), y int references t2(y), z int references t3(z)); create table t4 (a int primary key, x int references t1(x), y int references t2(y), z int references t3(z));
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlf-shadow-3-t1.frm #sqlf-shadow-t2.frm
#sqlf-shadow-3-t3.frm #sqlf-shadow-t3.frm
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
...@@ -834,19 +834,19 @@ set @@debug_dbug= "+d,crash_fk_backup_frm"; ...@@ -834,19 +834,19 @@ set @@debug_dbug= "+d,crash_fk_backup_frm";
create table t4 (a int primary key, x int references t1(x), y int references t2(y), z int references t3(z)); create table t4 (a int primary key, x int references t1(x), y int references t2(y), z int references t3(z));
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlf-shadow-3-t1.frm #sqlf-shadow-t1.frm
#sqlf-shadow-3-t2.frm #sqlf-shadow-t2.frm
#sqlf-shadow-3-t3.frm #sqlf-shadow-t3.frm
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
t1.fbk t1.frm
t2.MYD t2.MYD
t2.MYI t2.MYI
t2.fbk t2.fbk
t3.MYD t3.MYD
t3.MYI t3.MYI
t3.frm t3.fbk
t4.frm t4.frm
# State after crash recovery # State after crash recovery
db.opt db.opt
...@@ -901,12 +901,11 @@ set @@debug_dbug= "+d,crash_fk_install_shadow_frm"; ...@@ -901,12 +901,11 @@ set @@debug_dbug= "+d,crash_fk_install_shadow_frm";
create table t4 (a int primary key, x int references t1(x), y int references t2(y), z int references t3(z)); create table t4 (a int primary key, x int references t1(x), y int references t2(y), z int references t3(z));
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlf-shadow-3-t3.frm #sqlf-shadow-t1.frm
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
t1.fbk t1.fbk
t1.frm
t2.MYD t2.MYD
t2.MYI t2.MYI
t2.fbk t2.fbk
...@@ -914,6 +913,7 @@ t2.frm ...@@ -914,6 +913,7 @@ t2.frm
t3.MYD t3.MYD
t3.MYI t3.MYI
t3.fbk t3.fbk
t3.frm
t4.frm t4.frm
# State after crash recovery # State after crash recovery
db.opt db.opt
...@@ -1217,27 +1217,26 @@ test.t3 check Note Found 1 self-references ...@@ -1217,27 +1217,26 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,crash_fk_backup_frm"; set @@debug_dbug= "+d,crash_fk_write_shadow_frm";
rename table t4 to xt4, t1 to xt1, t3 to xt3, t2 to xt2; rename table t4 to xt4, t1 to xt1, t3 to xt3, t2 to xt2;
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlf-shadow-3-xt1.frm #sqlf-shadow-xt2.frm
#sqlf-shadow-3-xt2.frm #sqlf-shadow-xt3.frm
#sqlf-shadow-3-xt3.frm #sqlf-shadow-xt4.frm
#sqlf-shadow-3-xt4.frm
db.opt db.opt
xt1.MYD xt1.MYD
xt1.MYI xt1.MYI
xt1.fbk xt1.frm
xt2.MYD xt2.MYD
xt2.MYI xt2.MYI
xt2.frm xt2.frm
xt3.MYD xt3.MYD
xt3.MYI xt3.MYI
xt3.fbk xt3.frm
xt4.MYD xt4.MYD
xt4.MYI xt4.MYI
xt4.fbk xt4.frm
# State after crash recovery # State after crash recovery
db.opt db.opt
xt1.MYD xt1.MYD
...@@ -1316,24 +1315,24 @@ test.t3 check Note Found 1 self-references ...@@ -1316,24 +1315,24 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,crash_fk_install_shadow_frm"; set @@debug_dbug= "+d,crash_fk_backup_frm";
rename table t4 to xt4, t1 to xt1, t3 to xt3, t2 to xt2; rename table t4 to xt4, t1 to xt1, t3 to xt3, t2 to xt2;
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlf-shadow-3-xt4.frm #sqlf-shadow-xt1.frm
#sqlf-shadow-xt2.frm
#sqlf-shadow-xt3.frm
#sqlf-shadow-xt4.frm
db.opt db.opt
xt1.MYD xt1.MYD
xt1.MYI xt1.MYI
xt1.fbk
xt1.frm xt1.frm
xt2.MYD xt2.MYD
xt2.MYI xt2.MYI
xt2.fbk xt2.fbk
xt2.frm
xt3.MYD xt3.MYD
xt3.MYI xt3.MYI
xt3.fbk xt3.fbk
xt3.frm
xt4.MYD xt4.MYD
xt4.MYI xt4.MYI
xt4.fbk xt4.fbk
...@@ -1386,7 +1385,7 @@ test.t3 check Note Found 1 self-references ...@@ -1386,7 +1385,7 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
# State before failure # State before crash
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
...@@ -1415,23 +1414,44 @@ test.t3 check Note Found 1 self-references ...@@ -1415,23 +1414,44 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_write_shadow_frm"; set @@debug_dbug= "+d,crash_fk_install_shadow_frm";
alter table t3 rename xt3; rename table t4 to xt4, t1 to xt1, t3 to xt3, t2 to xt2;
ERROR HY000: Unknown error ERROR HY000: Lost connection to MySQL server during query
# State after failure # State after crash (before recovery)
#sqlf-shadow-xt1.frm
db.opt db.opt
t1.MYD xt1.MYD
t1.MYI xt1.MYI
t1.frm xt1.fbk
t2.MYD xt2.MYD
t2.MYI xt2.MYI
t2.frm xt2.fbk
t3.MYD xt2.frm
t3.MYI xt3.MYD
t3.frm xt3.MYI
t4.MYD xt3.fbk
t4.MYI xt3.frm
t4.frm xt4.MYD
xt4.MYI
xt4.fbk
xt4.frm
# State after crash recovery
db.opt
xt1.MYD
xt1.MYI
xt1.frm
xt2.MYD
xt2.MYI
xt2.frm
xt3.MYD
xt3.MYI
xt3.frm
xt4.MYD
xt4.MYI
xt4.frm
set foreign_key_checks= 0;
rename table xt4 to t4, xt3 to t3, xt2 to t2, xt1 to t1;
set foreign_key_checks= 1;
check tables t1, t2, t3, t4; check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys test.t1 check Note Found 2 referenced keys
...@@ -1493,7 +1513,7 @@ test.t3 check Note Found 1 self-references ...@@ -1493,7 +1513,7 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_backup_frm"; set @@debug_dbug= "+d,fail_fk_write_shadow_frm";
alter table t3 rename xt3; alter table t3 rename xt3;
ERROR HY000: Unknown error ERROR HY000: Unknown error
# State after failure # State after failure
...@@ -1571,7 +1591,7 @@ test.t3 check Note Found 1 self-references ...@@ -1571,7 +1591,7 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_install_shadow_frm"; set @@debug_dbug= "+d,fail_fk_backup_frm";
alter table t3 rename xt3; alter table t3 rename xt3;
ERROR HY000: Unknown error ERROR HY000: Unknown error
# State after failure # State after failure
...@@ -1604,9 +1624,6 @@ test.t3 check status OK ...@@ -1604,9 +1624,6 @@ test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set session debug_dbug=@save_dbug; set session debug_dbug=@save_dbug;
call drop_tables;
# RENAME COLUMN
call make_tables;
set @save_dbug=@@debug_dbug; set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4; check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
...@@ -1652,8 +1669,8 @@ test.t3 check Note Found 1 self-references ...@@ -1652,8 +1669,8 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_write_shadow_frm"; set @@debug_dbug= "+d,fail_fk_install_shadow_frm";
alter table t2 change y z int, change x y int, change b c int; alter table t3 rename xt3;
ERROR HY000: Unknown error ERROR HY000: Unknown error
# State after failure # State after failure
db.opt db.opt
...@@ -1701,7 +1718,7 @@ test.t3 check Note Found 1 self-references ...@@ -1701,7 +1718,7 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
# State before failure # State before crash
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
...@@ -1730,10 +1747,25 @@ test.t3 check Note Found 1 self-references ...@@ -1730,10 +1747,25 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_backup_frm"; set @@debug_dbug= "+d,crash_fk_write_shadow_frm";
alter table t2 change y z int, change x y int, change b c int; alter table t3 rename xt3;
ERROR HY000: Unknown error ERROR HY000: Lost connection to MySQL server during query
# State after failure # State after crash (before recovery)
#sqlf-shadow-t4.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
# State after crash recovery
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
...@@ -1779,7 +1811,7 @@ test.t3 check Note Found 1 self-references ...@@ -1779,7 +1811,7 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
# State before failure # State before crash
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
...@@ -1808,10 +1840,26 @@ test.t3 check Note Found 1 self-references ...@@ -1808,10 +1840,26 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_install_shadow_frm"; set @@debug_dbug= "+d,crash_fk_backup_frm";
alter table t2 change y z int, change x y int, change b c int; alter table t3 rename xt3;
ERROR HY000: Unknown error ERROR HY000: Lost connection to MySQL server during query
# State after failure # State after crash (before recovery)
#sqlf-shadow-t2.frm
#sqlf-shadow-t4.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.fbk
# State after crash recovery
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
...@@ -1857,7 +1905,7 @@ test.t3 check Note Found 1 self-references ...@@ -1857,7 +1905,7 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
# State before failure # State before crash
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
...@@ -1886,10 +1934,26 @@ test.t3 check Note Found 1 self-references ...@@ -1886,10 +1934,26 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_backup_frm"; set @@debug_dbug= "+d,crash_fk_install_shadow_frm";
alter table t3 rename column z to z2, rename column y to y2, rename column x to x2, rename column c to c2; alter table t3 rename xt3;
ERROR HY000: Unknown error ERROR HY000: Lost connection to MySQL server during query
# State after failure # State after crash (before recovery)
#sqlf-shadow-t2.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.fbk
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.fbk
t4.frm
# State after crash recovery
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
...@@ -1919,6 +1983,9 @@ test.t3 check status OK ...@@ -1919,6 +1983,9 @@ test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set session debug_dbug=@save_dbug; set session debug_dbug=@save_dbug;
call drop_tables;
# RENAME COLUMN
call make_tables;
set @save_dbug=@@debug_dbug; set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4; check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
...@@ -1964,8 +2031,8 @@ test.t3 check Note Found 1 self-references ...@@ -1964,8 +2031,8 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_install_shadow_frm"; set @@debug_dbug= "+d,fail_fk_write_shadow_frm";
alter table t3 rename column z to z2, rename column y to y2, rename column x to x2, rename column c to c2; alter table t2 change y z int, change x y int, change b c int;
ERROR HY000: Unknown error ERROR HY000: Unknown error
# State after failure # State after failure
db.opt db.opt
...@@ -1997,24 +2064,6 @@ test.t3 check status OK ...@@ -1997,24 +2064,6 @@ test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set session debug_dbug=@save_dbug; set session debug_dbug=@save_dbug;
call drop_tables;
# ADD/DROP FOREIGN KEY, DROP COLUMN
call make_tables;
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`x` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL,
`z` int(11) NOT NULL,
`c` int(11) DEFAULT NULL,
PRIMARY KEY (`z`),
KEY `fk_t3` (`x`),
KEY `fk_t3_2` (`y`),
KEY `fk_t3_3` (`c`),
CONSTRAINT `fk_t3` FOREIGN KEY (`x`) REFERENCES `t2` (`x`),
CONSTRAINT `fk_t3_2` FOREIGN KEY (`y`) REFERENCES `t2` (`y`),
CONSTRAINT `fk_t3_3` FOREIGN KEY (`c`) REFERENCES `t3` (`z`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
set @save_dbug=@@debug_dbug; set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4; check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
...@@ -2060,14 +2109,8 @@ test.t3 check Note Found 1 self-references ...@@ -2060,14 +2109,8 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_write_shadow_frm"; set @@debug_dbug= "+d,fail_fk_backup_frm";
alter table t3 alter table t2 change y z int, change x y int, change b c int;
drop foreign key fk_t3,
drop foreign key fk_t3_2,
drop foreign key fk_t3_3,
drop c,
add foreign key (x) references t1(x),
add foreign key (y) references t2(x);
ERROR HY000: Unknown error ERROR HY000: Unknown error
# State after failure # State after failure
db.opt db.opt
...@@ -2144,14 +2187,8 @@ test.t3 check Note Found 1 self-references ...@@ -2144,14 +2187,8 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_backup_frm"; set @@debug_dbug= "+d,fail_fk_install_shadow_frm";
alter table t3 alter table t2 change y z int, change x y int, change b c int;
drop foreign key fk_t3,
drop foreign key fk_t3_2,
drop foreign key fk_t3_3,
drop c,
add foreign key (x) references t1(x),
add foreign key (y) references t2(x);
ERROR HY000: Unknown error ERROR HY000: Unknown error
# State after failure # State after failure
db.opt db.opt
...@@ -2199,7 +2236,7 @@ test.t3 check Note Found 1 self-references ...@@ -2199,7 +2236,7 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
# State before failure # State before crash
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
...@@ -2228,16 +2265,1112 @@ test.t3 check Note Found 1 self-references ...@@ -2228,16 +2265,1112 @@ test.t3 check Note Found 1 self-references
test.t3 check status OK test.t3 check status OK
test.t4 check Note Found 3 foreign keys test.t4 check Note Found 3 foreign keys
test.t4 check status OK test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_install_shadow_frm"; set @@debug_dbug= "+d,crash_fk_write_shadow_frm";
alter table t3 alter table t2 change y z int, change x y int, change b c int;
drop foreign key fk_t3, ERROR HY000: Lost connection to MySQL server during query
drop foreign key fk_t3_2, # State after crash (before recovery)
drop foreign key fk_t3_3, #sql-alter-3.frm
drop c, #sqlf-shadow-t4.frm
add foreign key (x) references t1(x), db.opt
add foreign key (y) references t2(x); t1.MYD
ERROR HY000: Unknown error t1.MYI
# State after failure t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
# State after crash recovery
#sql-alter-3.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before crash
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,crash_fk_backup_frm";
alter table t2 change y z int, change x y int, change b c int;
ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery)
#sql-alter-3.frm
#sqlf-shadow-t3.frm
#sqlf-shadow-t4.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.fbk
# State after crash recovery
#sql-alter-3.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before crash
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,crash_fk_install_shadow_frm";
alter table t2 change y z int, change x y int, change b c int;
ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery)
#sql-alter-3.frm
#sqlf-shadow-t3.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.fbk
t4.MYD
t4.MYI
t4.fbk
t4.frm
# State after crash recovery
#sql-alter-3.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_write_shadow_frm";
alter table t3 rename column z to z2, rename column y to y2, rename column x to x2, rename column c to c2;
ERROR HY000: Unknown error
# State after failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_backup_frm";
alter table t3 rename column z to z2, rename column y to y2, rename column x to x2, rename column c to c2;
ERROR HY000: Unknown error
# State after failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_install_shadow_frm";
alter table t3 rename column z to z2, rename column y to y2, rename column x to x2, rename column c to c2;
ERROR HY000: Unknown error
# State after failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before crash
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,crash_fk_write_shadow_frm";
alter table t3 rename column z to z2, rename column y to y2, rename column x to x2, rename column c to c2;
ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery)
#sql-alter-3.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
# State after crash recovery
#sql-alter-3.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before crash
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,crash_fk_backup_frm";
alter table t3 rename column z to z2, rename column y to y2, rename column x to x2, rename column c to c2;
ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery)
#sql-alter-3.frm
#sqlf-shadow-t4.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
# State after crash recovery
#sql-alter-3.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before crash
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,crash_fk_install_shadow_frm";
alter table t3 rename column z to z2, rename column y to y2, rename column x to x2, rename column c to c2;
ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery)
#sql-alter-3.frm
#sqlf-shadow-t4.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.fbk
# State after crash recovery
#sql-alter-3.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
call drop_tables;
# ADD/DROP FOREIGN KEY, DROP COLUMN
call make_tables;
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`x` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL,
`z` int(11) NOT NULL,
`c` int(11) DEFAULT NULL,
PRIMARY KEY (`z`),
KEY `fk_t3` (`x`),
KEY `fk_t3_2` (`y`),
KEY `fk_t3_3` (`c`),
CONSTRAINT `fk_t3` FOREIGN KEY (`x`) REFERENCES `t2` (`x`),
CONSTRAINT `fk_t3_2` FOREIGN KEY (`y`) REFERENCES `t2` (`y`),
CONSTRAINT `fk_t3_3` FOREIGN KEY (`c`) REFERENCES `t3` (`z`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_write_shadow_frm";
alter table t3
drop foreign key fk_t3,
drop foreign key fk_t3_2,
drop foreign key fk_t3_3,
drop c,
add foreign key (x) references t1(x),
add foreign key (y) references t2(x);
ERROR HY000: Unknown error
# State after failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_backup_frm";
alter table t3
drop foreign key fk_t3,
drop foreign key fk_t3_2,
drop foreign key fk_t3_3,
drop c,
add foreign key (x) references t1(x),
add foreign key (y) references t2(x);
ERROR HY000: Unknown error
# State after failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,fail_fk_install_shadow_frm";
alter table t3
drop foreign key fk_t3,
drop foreign key fk_t3_2,
drop foreign key fk_t3_3,
drop c,
add foreign key (x) references t1(x),
add foreign key (y) references t2(x);
ERROR HY000: Unknown error
# State after failure
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set session debug_dbug=@save_dbug;
set @save_dbug=@@debug_dbug;
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
# State before crash
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
check tables t1, t2, t3, t4;
Table Op Msg_type Msg_text
test.t1 check Note Found 2 referenced keys
test.t1 check Note Found 1 self-references
test.t1 check status OK
test.t2 check Note Found 3 referenced keys
test.t2 check Note Found 1 foreign keys
test.t2 check Note Found 1 self-references
test.t2 check status OK
test.t3 check Note Found 1 referenced keys
test.t3 check Note Found 2 foreign keys
test.t3 check Note Found 1 self-references
test.t3 check status OK
test.t4 check Note Found 3 foreign keys
test.t4 check status OK
set @@debug_dbug= "+d,crash_fk_write_shadow_frm";
alter table t3
drop foreign key fk_t3,
drop foreign key fk_t3_2,
drop foreign key fk_t3_3,
drop c,
add foreign key (x) references t1(x),
add foreign key (y) references t2(x);
ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery)
#sql-alter-3.MYD
#sql-alter-3.MYI
#sql-alter-3.frm
#sqlf-shadow-t2.frm
db.opt
t1.MYD
t1.MYI
t1.frm
t2.MYD
t2.MYI
t2.frm
t3.MYD
t3.MYI
t3.frm
t4.MYD
t4.MYI
t4.frm
# State after crash recovery
#sql-alter-3.MYD
#sql-alter-3.MYI
#sql-alter-3.frm
db.opt db.opt
t1.MYD t1.MYD
t1.MYI t1.MYI
......
--source include/have_innodb.inc --source include/have_innodb.inc
--source include/have_debug.inc --source include/have_debug.inc
# Don't test this under valgrind, memory leaks will occur
--source include/not_valgrind.inc
# Crash tests don't work with embedded
--source include/not_embedded.inc
# In fail_fk_backup_frm the log is already written but rename is not done # In fail_fk_backup_frm the log is already written but rename is not done
call mtr.add_suppression("Failed to execute action for entry"); call mtr.add_suppression("Failed to execute action for entry");
...@@ -60,8 +64,6 @@ let $debug_dbug="+d,crash_fk_install_shadow_frm"; ...@@ -60,8 +64,6 @@ let $debug_dbug="+d,crash_fk_install_shadow_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
call drop_tables; call drop_tables;
# FIXME: crash statements
--echo # CREATE TABLE --echo # CREATE TABLE
create table t1 (x int primary key); create table t1 (x int primary key);
create table t2 (y int primary key); create table t2 (y int primary key);
...@@ -100,11 +102,13 @@ let $debug_dbug="+d,fail_fk_backup_frm"; ...@@ -100,11 +102,13 @@ let $debug_dbug="+d,fail_fk_backup_frm";
let $debug_dbug="+d,fail_fk_install_shadow_frm"; let $debug_dbug="+d,fail_fk_install_shadow_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
let $crash_statement= $fail_statement; let $crash_statement= $fail_statement;
# TODO: rollback RENAME TABLE (and other DDL?) via DDL log # TODO: RENAME TABLE is not crash-safe itself, so rollback it via DDL log
# NB: if we rename back in different order we'll lose some referenced hints # NB: if we rename back in different order we'll lose some referenced hints
# (Foreign_key_io::parse() skips them if it can't find table by name) # (Foreign_key_io::parse() skips them if it can't find table by name)
# MDEV-23433 solves the problem of missing referenced hints # MDEV-23433 solves the problem of missing referenced hints
let $fixup_statement= rename table xt4 to t4, xt3 to t3, xt2 to t2, xt1 to t1; let $fixup_statement= rename table xt4 to t4, xt3 to t3, xt2 to t2, xt1 to t1;
let $debug_dbug="+d,crash_fk_write_shadow_frm";
--source include/foreign_fail.inc
let $debug_dbug="+d,crash_fk_backup_frm"; let $debug_dbug="+d,crash_fk_backup_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
let $debug_dbug="+d,crash_fk_install_shadow_frm"; let $debug_dbug="+d,crash_fk_install_shadow_frm";
...@@ -118,11 +122,13 @@ let $debug_dbug="+d,fail_fk_backup_frm"; ...@@ -118,11 +122,13 @@ let $debug_dbug="+d,fail_fk_backup_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
let $debug_dbug="+d,fail_fk_install_shadow_frm"; let $debug_dbug="+d,fail_fk_install_shadow_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
#let $crash_statement= $fail_statement; let $crash_statement= $fail_statement;
#let $debug_dbug="+d,crash_fk_backup_frm"; let $debug_dbug="+d,crash_fk_write_shadow_frm";
#--source include/foreign_fail.inc --source include/foreign_fail.inc
#let $debug_dbug="+d,crash_fk_install_shadow_frm"; let $debug_dbug="+d,crash_fk_backup_frm";
#--source include/foreign_fail.inc --source include/foreign_fail.inc
let $debug_dbug="+d,crash_fk_install_shadow_frm";
--source include/foreign_fail.inc
call drop_tables; call drop_tables;
--echo # RENAME COLUMN --echo # RENAME COLUMN
...@@ -136,16 +142,34 @@ let $debug_dbug="+d,fail_fk_backup_frm"; ...@@ -136,16 +142,34 @@ let $debug_dbug="+d,fail_fk_backup_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
let $debug_dbug="+d,fail_fk_install_shadow_frm"; let $debug_dbug="+d,fail_fk_install_shadow_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
let $crash_statement= $fail_statement;
let $debug_dbug="+d,crash_fk_write_shadow_frm";
--source include/foreign_fail.inc
let $debug_dbug="+d,crash_fk_backup_frm";
--source include/foreign_fail.inc
let $debug_dbug="+d,crash_fk_install_shadow_frm";
--source include/foreign_fail.inc
let $fail_statement= alter table t3 rename column z to z2, rename column y to y2, rename column x to x2, rename column c to c2; let $fail_statement= alter table t3 rename column z to z2, rename column y to y2, rename column x to x2, rename column c to c2;
--let $crash_statement=
let $debug_dbug="+d,fail_fk_write_shadow_frm";
--source include/foreign_fail.inc
let $debug_dbug="+d,fail_fk_backup_frm"; let $debug_dbug="+d,fail_fk_backup_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
let $debug_dbug="+d,fail_fk_install_shadow_frm"; let $debug_dbug="+d,fail_fk_install_shadow_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
let $crash_statement= $fail_statement;
let $debug_dbug="+d,crash_fk_write_shadow_frm";
--source include/foreign_fail.inc
let $debug_dbug="+d,crash_fk_backup_frm";
--source include/foreign_fail.inc
let $debug_dbug="+d,crash_fk_install_shadow_frm";
--source include/foreign_fail.inc
call drop_tables; call drop_tables;
--echo # ADD/DROP FOREIGN KEY, DROP COLUMN --echo # ADD/DROP FOREIGN KEY, DROP COLUMN
call make_tables; call make_tables;
--let $create_statement= --let $create_statement=
--let $crash_statement=
show create table t3; show create table t3;
let $fail_statement= alter table t3 let $fail_statement= alter table t3
drop foreign key fk_t3, drop foreign key fk_t3,
...@@ -160,18 +184,16 @@ let $debug_dbug="+d,fail_fk_backup_frm"; ...@@ -160,18 +184,16 @@ let $debug_dbug="+d,fail_fk_backup_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
let $debug_dbug="+d,fail_fk_install_shadow_frm"; let $debug_dbug="+d,fail_fk_install_shadow_frm";
--source include/foreign_fail.inc --source include/foreign_fail.inc
let $crash_statement= $fail_statement;
let $debug_dbug="+d,crash_fk_write_shadow_frm";
--source include/foreign_fail.inc
# TODO: ALTER TABLE is not crash-safe itself, so rollback it via DDL log
#let $debug_dbug="+d,crash_fk_backup_frm";
#--source include/foreign_fail.inc
#let $debug_dbug="+d,crash_fk_install_shadow_frm";
#--source include/foreign_fail.inc
call drop_tables; call drop_tables;
#set @save_dbug=@@debug_dbug;
#let $create_statement= create or replace table t1 (id int primary key);
#let $create_statement2= create or replace table t2 (id int);
#let $insert_statement= insert into t1 values(1);
#let $insert_statement2= insert into t2 values(1);
#set session debug_dbug="+d,crash_fk_alter_1";
#let $crash_statement= alter table t2 add foreign key (id) references t1(id), algorithm=copy;
#--source suite/parts/inc/partition_crash_t2.inc
drop procedure make_tables; drop procedure make_tables;
drop procedure drop_tables; drop procedure drop_tables;
set session debug_dbug=@save_dbug; set session debug_dbug=@save_dbug;
...@@ -388,13 +388,7 @@ a b ...@@ -388,13 +388,7 @@ a b
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlx-nnnn_nnnn.ibd #sql-exchange.frm
db.opt
t1#P#p0.ibd
t1#P#p1.ibd
t1.frm
t1.par
t2.frm
# State after crash recovery # State after crash recovery
db.opt db.opt
t1#P#p0.ibd t1#P#p0.ibd
...@@ -496,13 +490,7 @@ a b ...@@ -496,13 +490,7 @@ a b
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlx-nnnn_nnnn.ibd #sql-exchange.frm
db.opt
t1#P#p0.ibd
t1#P#p1.ibd
t1.frm
t1.par
t2.frm
# State after crash recovery # State after crash recovery
db.opt db.opt
t1#P#p0.ibd t1#P#p0.ibd
...@@ -604,13 +592,7 @@ a b ...@@ -604,13 +592,7 @@ a b
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlx-nnnn_nnnn.ibd #sql-exchange.ibd
db.opt
t1#P#p1.ibd
t1.frm
t1.par
t2.frm
t2.ibd
# State after crash recovery # State after crash recovery
db.opt db.opt
t1#P#p0.ibd t1#P#p0.ibd
...@@ -712,13 +694,7 @@ a b ...@@ -712,13 +694,7 @@ a b
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
ERROR HY000: Lost connection to MySQL server during query ERROR HY000: Lost connection to MySQL server during query
# State after crash (before recovery) # State after crash (before recovery)
#sqlx-nnnn_nnnn.ibd #sql-exchange.ibd
db.opt
t1#P#p1.ibd
t1.frm
t1.par
t2.frm
t2.ibd
# State after crash recovery # State after crash recovery
db.opt db.opt
t1#P#p0.ibd t1#P#p0.ibd
......
...@@ -767,7 +767,7 @@ void FK_backup_storage::drop_backup_frms(THD *thd) ...@@ -767,7 +767,7 @@ void FK_backup_storage::drop_backup_frms(THD *thd)
continue; continue;
if (deactivate_ddl_log_entry(bak.second.restore_backup_entry->entry_pos)) if (deactivate_ddl_log_entry(bak.second.restore_backup_entry->entry_pos))
{ {
// FIXME: test getting into here (and other deactivate_ddl_log_entry() failures) // TODO: test getting into here (and other deactivate_ddl_log_entry() failures)
my_printf_error(ER_DDL_LOG_ERROR, "Deactivating restore backup entry %u failed", my_printf_error(ER_DDL_LOG_ERROR, "Deactivating restore backup entry %u failed",
MYF(0), bak.second.restore_backup_entry->entry_pos); MYF(0), bak.second.restore_backup_entry->entry_pos);
// TODO: must be atomic // TODO: must be atomic
......
...@@ -1023,7 +1023,7 @@ class FK_share_backup : public FK_backup ...@@ -1023,7 +1023,7 @@ class FK_share_backup : public FK_backup
}; };
// NB: FK_ddl_backup responds for share release unlike FK_table_backup // NB: FK_ddl_backup responds for share release unlike FK_share_backup
class FK_ddl_backup : public FK_share_backup class FK_ddl_backup : public FK_share_backup
{ {
/* NB: if sa.share is not empty, share is auto-released on destructor */ /* NB: if sa.share is not empty, share is auto-released on destructor */
...@@ -1032,7 +1032,7 @@ class FK_ddl_backup : public FK_share_backup ...@@ -1032,7 +1032,7 @@ class FK_ddl_backup : public FK_share_backup
NB: if sa.share is not empty, share == sa.share. ALTER algorithms are more NB: if sa.share is not empty, share == sa.share. ALTER algorithms are more
complex and shares are held and released in separate container alter_ctx.fk_shares. complex and shares are held and released in separate container alter_ctx.fk_shares.
To make DDL logging common for all commands we handle it via FK_backup_storage interface, but To make DDL logging common for all commands we handle it via FK_backup_storage interface, but
without templating and virtual interfaces (these are overcomplexity for only 2 variations) without templating and virtual interfaces (these are overcomplexity for only 2 variants)
we have to converge backup operations into single FK_ddl_backup. we have to converge backup operations into single FK_ddl_backup.
*/ */
...@@ -1057,6 +1057,17 @@ class FK_ddl_backup : public FK_share_backup ...@@ -1057,6 +1057,17 @@ class FK_ddl_backup : public FK_share_backup
bool backup_frm(ddl_log_info &log_info, Table_name table); bool backup_frm(ddl_log_info &log_info, Table_name table);
}; };
#ifndef DBUG_OFF
// NB: we do want definite order of shares in test cases
struct TABLE_SHARE_by_name
{
bool operator() (const TABLE_SHARE *s1, const TABLE_SHARE *s2) const
{
return s1->cmp_db_table(s2->db, s2->table_name) < 0;
}
};
#endif
/* /*
NB: again, ALTER does require duplicate check hence mbd::map is used, while other commands NB: again, ALTER does require duplicate check hence mbd::map is used, while other commands
...@@ -1064,7 +1075,12 @@ class FK_ddl_backup : public FK_share_backup ...@@ -1064,7 +1075,12 @@ class FK_ddl_backup : public FK_share_backup
ifaces we just use mbd::map for everything. We are not going to hit bottleneck here: ifaces we just use mbd::map for everything. We are not going to hit bottleneck here:
it is DDL (rare operation), it is less than hundred of foreign keys normally. it is DDL (rare operation), it is less than hundred of foreign keys normally.
*/ */
class FK_backup_storage: public mbd::map<TABLE_SHARE *, FK_ddl_backup>, public ddl_log_info class FK_backup_storage: public mbd::map<TABLE_SHARE *, FK_ddl_backup
#ifndef DBUG_OFF
, TABLE_SHARE_by_name
#endif
>,
public ddl_log_info
{ {
public: public:
int write_shadow_frms(); int write_shadow_frms();
......
...@@ -348,8 +348,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, const LEX_CSTRING *new_db, ...@@ -348,8 +348,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, const LEX_CSTRING *new_db,
Shared table. Just drop the old .frm as it's not correct anymore Shared table. Just drop the old .frm as it's not correct anymore
Discovery will find the old table when it's accessed Discovery will find the old table when it's accessed
*/ */
// FIXME: tdc_remove_table() is now done later. Does that work? tdc_remove_table(thd, ren_table->db.str, ren_table->table_name.str);
// tdc_remove_table(thd, ren_table->db.str, ren_table->table_name.str);
quick_rm_table(thd, 0, &ren_table->db, &old_alias, FRM_ONLY, 0); quick_rm_table(thd, 0, &ren_table->db, &old_alias, FRM_ONLY, 0);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -8191,7 +8191,8 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -8191,7 +8191,8 @@ static bool mysql_inplace_alter_table(THD *thd,
if (wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_RENAME)) if (wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_RENAME))
goto rollback; goto rollback;
if (alter_ctx->fk_handle_alter(thd)) if (alter_ctx->fk_handle_alter(thd) ||
alter_ctx->fk_ref_backup.install_shadow_frms())
goto rollback; goto rollback;
/* Set MDL_BACKUP_DDL */ /* Set MDL_BACKUP_DDL */
...@@ -8262,13 +8263,15 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -8262,13 +8263,15 @@ static bool mysql_inplace_alter_table(THD *thd,
{ {
my_error(HA_ERR_INCOMPATIBLE_DEFINITION, MYF(0)); my_error(HA_ERR_INCOMPATIBLE_DEFINITION, MYF(0));
alter_ctx->fk_ref_backup.rollback(thd); alter_ctx->fk_ref_backup.rollback(thd);
// FIXME: why not goto rollback?
goto cleanup; goto cleanup;
} }
} }
table->s->frm_image= NULL; table->s->frm_image= NULL;
alter_ctx->fk_ref_backup.drop_backup_frms(thd);
alter_ctx->fk_ref_backup.clear();
close_all_tables_for_name(thd, table->s, close_all_tables_for_name(thd, table->s,
alter_ctx->is_table_renamed() ? alter_ctx->is_table_renamed() ?
HA_EXTRA_PREPARE_FOR_RENAME : HA_EXTRA_PREPARE_FOR_RENAME :
...@@ -8276,15 +8279,6 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -8276,15 +8279,6 @@ static bool mysql_inplace_alter_table(THD *thd,
NULL); NULL);
table_list->table= table= NULL; table_list->table= table= NULL;
// FIXME: do right after fk_handle_alter?
if (alter_ctx->fk_ref_backup.install_shadow_frms())
{
alter_ctx->fk_ref_backup.rollback(thd);
DBUG_RETURN(true);
}
alter_ctx->fk_ref_backup.drop_backup_frms(thd);
/* /*
Replace the old .FRM with the new .FRM, but keep the old name for now. Replace the old .FRM with the new .FRM, but keep the old name for now.
Rename to the new name (if needed) will be handled separately below. Rename to the new name (if needed) will be handled separately below.
...@@ -8310,7 +8304,6 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -8310,7 +8304,6 @@ static bool mysql_inplace_alter_table(THD *thd,
if (mysql_rename_table(db_type, &alter_ctx->db, &alter_ctx->table_name, if (mysql_rename_table(db_type, &alter_ctx->db, &alter_ctx->table_name,
&alter_ctx->new_db, &alter_ctx->new_alias, 0)) &alter_ctx->new_db, &alter_ctx->new_alias, 0))
{ {
// FIXME: rollback only table name
/* /*
If the rename fails we will still have a working table If the rename fails we will still have a working table
with the old name, but with other changes applied. with the old name, but with other changes applied.
...@@ -8331,7 +8324,6 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -8331,7 +8324,6 @@ static bool mysql_inplace_alter_table(THD *thd,
(void) mysql_rename_table(db_type, (void) mysql_rename_table(db_type,
&alter_ctx->new_db, &alter_ctx->new_alias, &alter_ctx->new_db, &alter_ctx->new_alias,
&alter_ctx->db, &alter_ctx->alias, NO_FK_CHECKS); &alter_ctx->db, &alter_ctx->alias, NO_FK_CHECKS);
// FIXME: if rename succeeds rollback only table name
DBUG_RETURN(true); DBUG_RETURN(true);
} }
rename_table_in_stat_tables(thd, &alter_ctx->db, &alter_ctx->alias, rename_table_in_stat_tables(thd, &alter_ctx->db, &alter_ctx->alias,
...@@ -11252,6 +11244,7 @@ do_continue:; ...@@ -11252,6 +11244,7 @@ do_continue:;
if (wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_RENAME)) if (wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_RENAME))
goto err_new_table_cleanup; goto err_new_table_cleanup;
alter_ctx.fk_ref_backup.erase(table->s);
if (alter_ctx.fk_handle_alter(thd)) if (alter_ctx.fk_handle_alter(thd))
// NB: now after lock upgrade it jumps to "err_with_mdl" as well // NB: now after lock upgrade it jumps to "err_with_mdl" as well
goto err_new_table_cleanup; goto err_new_table_cleanup;
...@@ -13191,7 +13184,7 @@ bool fk_handle_rename(THD *thd, TABLE_LIST *old_table, const LEX_CSTRING *new_db ...@@ -13191,7 +13184,7 @@ bool fk_handle_rename(THD *thd, TABLE_LIST *old_table, const LEX_CSTRING *new_db
if (share->foreign_keys.is_empty() && share->referenced_keys.is_empty()) if (share->foreign_keys.is_empty() && share->referenced_keys.is_empty())
return false; return false;
mbd::set<Table_name> tables; mbd::set<Table_name> tables;
mbd::set<Table_name> already; // FIXME: do we need it for mbd::map? mbd::set<Table_name> already;
MDL_request_list mdl_list; MDL_request_list mdl_list;
for (auto &bak: fk_rename_backup) for (auto &bak: fk_rename_backup)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment