1 | Setup
|
---|
2 | ======
|
---|
3 |
|
---|
4 | CREATE TABLE t ( id INT NOT NULL AUTO_INCREMENT, from_id INT, to_id INT, PRIMARY KEY (id) );
|
---|
5 | INSERT INTO t (from_id, to_id) VALUES (10, 20);
|
---|
6 |
|
---|
7 | Session A Session B
|
---|
8 | ========= =========
|
---|
9 |
|
---|
10 | SET autocommit=0; SET autocommit=0;
|
---|
11 |
|
---|
12 | SELECT * FROM t; SELECT * FROM t;
|
---|
13 | +----+---------+-------+ +----+---------+-------+
|
---|
14 | | id | from_id | to_id | | id | from_id | to_id |
|
---|
15 | +----+---------+-------+ +----+---------+-------+
|
---|
16 | | 1 | 10 | 20 | | 1 | 10 | 20 |
|
---|
17 | +----+---------+-------+ +----+---------+-------+
|
---|
18 | 1 row in set 1 row in set
|
---|
19 |
|
---|
20 | DELETE FROM t WHERE from_id=10;
|
---|
21 | Query OK, 1 row affected
|
---|
22 |
|
---|
23 | SELECT * FROM t WHERE from_id=10 and to_id IN (20);
|
---|
24 | Empty set
|
---|
25 |
|
---|
26 | INSERT INTO t (from_id, to_id) VALUES (10, 20);
|
---|
27 | Query OK, 1 row affected
|
---|
28 |
|
---|
29 | COMMIT;
|
---|
30 | SET autocommit=1;
|
---|
31 |
|
---|
32 | DELETE FROM t WHERE from_id=10;
|
---|
33 | Query OK, 1 row affected
|
---|
34 |
|
---|
35 | SELECT * FROM t WHERE from_id=10 and to_id IN (20);
|
---|
36 | +----+---------+-------+
|
---|
37 | | id | from_id | to_id |
|
---|
38 | +----+---------+-------+
|
---|
39 | | 1 | 10 | 20 |
|
---|
40 | +----+---------+-------+
|
---|
41 | 1 row in set
|
---|
42 |
|
---|
43 | (Not inserting anything since "it's already there!")
|
---|
44 |
|
---|
45 | COMMIT;
|
---|
46 | SET autocommit=1;
|
---|
47 |
|
---|
48 | Later
|
---|
49 | =====
|
---|
50 |
|
---|
51 | SELECT * FROM t;
|
---|
52 | Empty set
|
---|