Debian Codegraph @

mysql-test/suite/innodb/t/deadlock_in_subqueries_join.test

raw
1 --source include/have_innodb.inc
2 --source include/count_sessions.inc
3
4 --disable_query_log
5 call mtr.add_suppression("InnoDB: Transaction was aborted due to ");
6 --enable_query_log
7
8 CREATE TABLE t1 (
9 pkey int NOT NULL PRIMARY KEY,
10 c int
11 ) ENGINE=InnoDB;
12
13 INSERT INTO t1 VALUES(1,1);
14
15 CREATE TABLE t2 (
16 pkey int NOT NULL PRIMARY KEY,
17 c int
18 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
19
20 INSERT INTO t2 VALUES (2, NULL);
21
22 # The following table is to increase tansaction weight on deadlock resolution
23 CREATE TABLE t3 (c int) engine = InnoDB;
24 INSERT INTO t3 VALUES (10), (20), (30), (40), (50);
25
26 --let $i= 2
27 --let $delete= 2
28 --let $update= 1
29 --connect(con1, localhost,root,,)
30
31 while($i) {
32 --connection default
33 START TRANSACTION; # trx 1
34 # The following update is necessary to increase the transaction weight, which is
35 # calculated as the number of locks + the number of undo records during deadlock
36 # report. Victim's transaction should have minimum weight. We need trx 2 to be
37 # choosen as victim, that's why we need to increase the current transaction
38 # weight.
39 UPDATE t3 SET c=c+1000;
40 SELECT * FROM t1 FOR UPDATE;
41
42 --connection con1
43 START TRANSACTION; # trx 2
44 # 1) read record from t2, lock it
45 # 2) check if the read record should be deleted, i.e. read record from t1,
46 # as the record from t1 is locked by trx 1, the subselect will be suspended.
47 # see 'while' loop in mysql_delete() or mysql_update() and
48 # select->skip_record(thd) call for details.
49 if ($i == $delete) {
50 --send DELETE FROM t2 WHERE c NOT IN (SELECT ref_0.pkey FROM t1 AS ref_0 INNER JOIN t1 AS ref_1 ON ref_0.c = ref_0.pkey)
51 }
52 if ($i == $update) {
53 --send UPDATE t2 SET pkey=pkey+10 WHERE c NOT IN (SELECT ref_0.pkey FROM t1 AS ref_0 INNER JOIN t1 AS ref_1 ON ref_0.c = ref_0.pkey)
54 }
55
56 --connection default
57 let $wait_condition=
58 SELECT count(*) = 1 FROM information_schema.processlist
59 WHERE (state = 'Sending data' OR state = "Updating")
60 AND (info LIKE 'delete from t2 where%' OR
61 info LIKE 'UPDATE t2 SET pkey=pkey+10 WHERE%');
62 --source include/wait_condition.inc
63
64 # The record from t2 is locked by the previous delete, so trx 2 is waiting for
65 # trx 1, and trx 1 will be blocked by trx 2 with the following SELECT. So we
66 # have deadlock here. And trx 2 is chosen as deadlock victim as trx 1 has
67 # greater weight.
68 SELECT * FROM t2 FOR UPDATE;
69 COMMIT;
70
71 --connection con1
72 # If the bug is not fixed, there will be assertion failure as
73 # mysql_delete()/mysql_update() will continue execution despite its subselect
74 # got deadlock error
75 --error ER_LOCK_DEADLOCK
76 --reap
77 COMMIT;
78 --dec $i
79 }
80
81 --disconnect con1
82
83 --connection default
84 DROP TABLE t1,t2,t3;
85 --source include/wait_until_count_sessions.inc