1# 2# Bug #18451287 REDUNDANT DELETE MARKING AFTER DB_LOCK_WAIT 3# 4create table t1 (f1 int primary key, f2 blob) engine=innodb; 5create table t2 (f1 int primary key, f2 int, 6foreign key (f2) references t1(f1) on update cascade) engine=innodb; 7show create table t1; 8Table Create Table 9t1 CREATE TABLE `t1` ( 10 `f1` int(11) NOT NULL, 11 `f2` blob DEFAULT NULL, 12 PRIMARY KEY (`f1`) 13) ENGINE=InnoDB DEFAULT CHARSET=latin1 14show create table t2; 15Table Create Table 16t2 CREATE TABLE `t2` ( 17 `f1` int(11) NOT NULL, 18 `f2` int(11) DEFAULT NULL, 19 PRIMARY KEY (`f1`), 20 KEY `f2` (`f2`), 21 CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE 22) ENGINE=InnoDB DEFAULT CHARSET=latin1 23insert into t1 values (1, repeat('+', 20000)); 24insert into t1 values (2, repeat('-', 20000)); 25insert into t1 values (3, repeat('=', 20000)); 26insert into t2 values (1, 2); 27select f1, right(f2, 20) as p2 from t1; 28f1 p2 291 ++++++++++++++++++++ 302 -------------------- 313 ==================== 32select f1, f2 from t2; 33f1 f2 341 2 35connect con1,localhost,root,,test; 36start transaction; 37select f1, f2 from t2 for update; 38f1 f2 391 2 40connection default; 41set debug_sync='lock_wait_suspend_thread_enter SIGNAL upd_waiting WAIT_FOR go_upd'; 42update t1 set f1 = 10 where f1 = 2; 43connection con1; 44set debug_sync='now WAIT_FOR upd_waiting'; 45rollback; 46set debug_sync='now SIGNAL go_upd'; 47connection default; 48# reap: update t1 set f1 = 10 where f1 = 2; 49select f1, right(f2, 20) as p2 from t1; 50f1 p2 511 ++++++++++++++++++++ 523 ==================== 5310 -------------------- 54select f1, f2 from t2; 55f1 f2 561 10 57drop table t2, t1; 58set debug_sync = reset; 59# 60# Test Scenario: Two tables t1 -> t2 are involved in update cascade. 61# If DB_LOCK_WAIT happens when t1 is being updated and FK constraints 62# are being checked in t2, then retry must happen on t1. The update 63# cascade happens in secondary index. For secondary index testing, 64# blobs are not needed. 65# 66create table t1 (f1 int primary key, f2 int, key k1(f2)) engine=innodb; 67create table t2 (f1 int primary key, f2 int, 68foreign key (f2) references t1(f2) on update cascade) engine=innodb; 69show create table t1; 70Table Create Table 71t1 CREATE TABLE `t1` ( 72 `f1` int(11) NOT NULL, 73 `f2` int(11) DEFAULT NULL, 74 PRIMARY KEY (`f1`), 75 KEY `k1` (`f2`) 76) ENGINE=InnoDB DEFAULT CHARSET=latin1 77show create table t2; 78Table Create Table 79t2 CREATE TABLE `t2` ( 80 `f1` int(11) NOT NULL, 81 `f2` int(11) DEFAULT NULL, 82 PRIMARY KEY (`f1`), 83 KEY `f2` (`f2`), 84 CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE 85) ENGINE=InnoDB DEFAULT CHARSET=latin1 86insert into t1 values (1, 91); 87insert into t2 values (1, 91); 88select f1, f2 from t1; 89f1 f2 901 91 91select f1, f2 from t2; 92f1 f2 931 91 94connection con1; 95start transaction; 96select f1, f2 from t2 for update; 97f1 f2 981 91 99connection default; 100set debug_sync='lock_wait_suspend_thread_enter SIGNAL upd_waiting WAIT_FOR go_upd'; 101update t1 set f2 = 28 where f2 = 91; 102connection con1; 103set debug_sync='now WAIT_FOR upd_waiting'; 104rollback; 105set debug_sync='now SIGNAL go_upd'; 106connection default; 107# reap: update t1 set f1 = 10 where f1 = 2; 108select f1, f2 from t1; 109f1 f2 1101 28 111select f1, f2 from t2; 112f1 f2 1131 28 114drop table t2, t1; 115set debug_sync = reset; 116# 117# Test Scenario: Three tables t1 -> t2 -> t3 are involved in update cascade. 118# If DB_LOCK_WAIT happens when t2 is being updated, then retry must happen 119# on t2. 120# 121create table t1 (f1 int primary key, f2 blob) engine=innodb; 122create table t2 (f1 int primary key, f2 blob, 123foreign key (f1) references t1(f1) on update cascade) engine=innodb; 124create table t3 (f1 int primary key, f2 blob, 125foreign key (f1) references t2(f1) on update cascade) engine=innodb; 126show create table t1; 127Table Create Table 128t1 CREATE TABLE `t1` ( 129 `f1` int(11) NOT NULL, 130 `f2` blob DEFAULT NULL, 131 PRIMARY KEY (`f1`) 132) ENGINE=InnoDB DEFAULT CHARSET=latin1 133show create table t2; 134Table Create Table 135t2 CREATE TABLE `t2` ( 136 `f1` int(11) NOT NULL, 137 `f2` blob DEFAULT NULL, 138 PRIMARY KEY (`f1`), 139 CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE 140) ENGINE=InnoDB DEFAULT CHARSET=latin1 141show create table t3; 142Table Create Table 143t3 CREATE TABLE `t3` ( 144 `f1` int(11) NOT NULL, 145 `f2` blob DEFAULT NULL, 146 PRIMARY KEY (`f1`), 147 CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t2` (`f1`) ON UPDATE CASCADE 148) ENGINE=InnoDB DEFAULT CHARSET=latin1 149insert into t1 values (2, repeat('-', 20000)); 150insert into t2 values (2, repeat('%', 20000)); 151insert into t3 values (2, repeat('+', 20000)); 152select f1, right(f2, 20) as p2 from t1; 153f1 p2 1542 -------------------- 155select f1, right(f2, 20) as p2 from t2; 156f1 p2 1572 %%%%%%%%%%%%%%%%%%%% 158select f1, right(f2, 20) as p2 from t3; 159f1 p2 1602 ++++++++++++++++++++ 161connection con1; 162start transaction; 163select f1 from t3 for update; 164f1 1652 166connection default; 167set debug_sync='lock_wait_suspend_thread_enter SIGNAL upd_waiting WAIT_FOR go_upd'; 168update t1 set f1 = 10 where f1 = 2; 169connection con1; 170set debug_sync='now WAIT_FOR upd_waiting'; 171rollback; 172# The table t1 is updated. 173# In t2 delete-mark happened. Retry will happen on t2. 174# In t3 yet to be updated. 175set session transaction isolation level read uncommitted; 176start transaction; 177select f1, right(f2, 20) as p2 from t1; 178f1 p2 179select f1, right(f2, 20) as p2 from t2; 180f1 p2 181select f1, right(f2, 20) as p2 from t3; 182f1 p2 1832 ++++++++++++++++++++ 184commit; 185set debug_sync='now SIGNAL go_upd'; 186connection default; 187# reap: update t1 set f1 = 10 where f1 = 2; 188start transaction; 189select f1, right(f2, 20) as p2 from t1; 190f1 p2 19110 -------------------- 192select f1, right(f2, 20) as p2 from t2; 193f1 p2 19410 %%%%%%%%%%%%%%%%%%%% 195select f1, right(f2, 20) as p2 from t3; 196f1 p2 19710 ++++++++++++++++++++ 198commit; 199drop table t3, t2, t1; 200set debug_sync = reset; 201# 202# Test Scenario: Three tables t1 -> t2 -> t3 are involved in update 203# cascade. If DB_LOCK_WAIT happens when t2 is being updated, then 204# retry must happen on t2. The update cascade is happening via 205# secondary index (hence blobs are not needed). 206# 207create table t1 (f1 int primary key, f2 int, key k1(f2)) engine=innodb; 208create table t2 (f1 int primary key, f2 int, 209foreign key (f2) references t1(f2) on update cascade) engine=innodb; 210create table t3 (f1 int primary key, f2 int, 211foreign key (f2) references t2(f2) on update cascade) engine=innodb; 212show create table t1; 213Table Create Table 214t1 CREATE TABLE `t1` ( 215 `f1` int(11) NOT NULL, 216 `f2` int(11) DEFAULT NULL, 217 PRIMARY KEY (`f1`), 218 KEY `k1` (`f2`) 219) ENGINE=InnoDB DEFAULT CHARSET=latin1 220show create table t2; 221Table Create Table 222t2 CREATE TABLE `t2` ( 223 `f1` int(11) NOT NULL, 224 `f2` int(11) DEFAULT NULL, 225 PRIMARY KEY (`f1`), 226 KEY `f2` (`f2`), 227 CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE 228) ENGINE=InnoDB DEFAULT CHARSET=latin1 229show create table t3; 230Table Create Table 231t3 CREATE TABLE `t3` ( 232 `f1` int(11) NOT NULL, 233 `f2` int(11) DEFAULT NULL, 234 PRIMARY KEY (`f1`), 235 KEY `f2` (`f2`), 236 CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t2` (`f2`) ON UPDATE CASCADE 237) ENGINE=InnoDB DEFAULT CHARSET=latin1 238insert into t1 values (2, 91); 239insert into t2 values (2, 91); 240insert into t3 values (2, 91); 241select f1, f2 from t1; 242f1 f2 2432 91 244select f1, f2 from t2; 245f1 f2 2462 91 247select f1, f2 from t3; 248f1 f2 2492 91 250connection con1; 251start transaction; 252select f1 from t3 for update; 253f1 2542 255connection default; 256set debug_sync='lock_wait_suspend_thread_enter SIGNAL upd_waiting WAIT_FOR go_upd'; 257update t1 set f2 = 28 where f2 = 91; 258connection con1; 259set debug_sync='now WAIT_FOR upd_waiting'; 260rollback; 261# The table t1 is updated. 262# In t2 delete-mark happened. Retry will happen on t2. 263# In t3 yet to be updated. 264set session transaction isolation level read uncommitted; 265start transaction; 266select f1, f2 from t1; 267f1 f2 268select f1, f2 from t2; 269f1 f2 270select f1, f2 from t3; 271f1 f2 2722 91 273commit; 274set debug_sync='now SIGNAL go_upd'; 275disconnect con1; 276connection default; 277# reap: update t1 set f2 = 28 where f2 = 91; 278start transaction; 279select f1, f2 from t1; 280f1 f2 2812 28 282select f1, f2 from t2; 283f1 f2 2842 28 285select f1, f2 from t3; 286f1 f2 2872 28 288commit; 289drop table t3, t2, t1; 290set debug_sync = reset; 291