*** Bug #28026 ***
SET @@storage_engine = 'Falcon';
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
------- Test 1 - with indexes -------
CREATE TABLE t1 (a int, PRIMARY KEY (a));
INSERT INTO t1 VALUES (8);
INSERT INTO t1 VALUES (9);
BEGIN;
INSERT INTO t1 VALUES (1);
SELECT * FROM t1 ORDER BY a;
a
1
8
9
SELECT * FROM t1 WHERE a = 8 FOR UPDATE;
a
8
# Establish and Switch to connection conn1
BEGIN;
INSERT INTO t1 VALUES (2);
SELECT * FROM t1 ORDER BY a;
a
2
8
9
SELECT * FROM t1 WHERE a = 9 FOR UPDATE;
a
9
SELECT * FROM t1 WHERE a = 8 FOR UPDATE;
# Switch to connection default
SELECT * FROM t1 WHERE a = 9 FOR UPDATE;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
SELECT * FROM t1 ORDER BY a;
a
1
8
9
ROLLBACK;
SELECT * FROM t1 ORDER BY a;
a
8
9
# Switch to connection conn1
UPDATE t1 SET a = 88 WHERE a = 8;
UPDATE t1 SET a = 99 WHERE a = 9;
SELECT * FROM t1 ORDER BY a;
a
2
88
99
COMMIT;
# Switch to connection default
COMMIT;
------- Test 2 - with partitions ------
CREATE TABLE t2 (a int)
PARTITION BY LIST (a) (
PARTITION p8 VALUES in (1,8,88),
PARTITION p9 VALUES in (2,9,99));
INSERT INTO t2 VALUES (8);
INSERT INTO t2 VALUES (9);
BEGIN;
INSERT INTO t2 VALUES (1);
SELECT * FROM t2 ORDER BY a;
a
1
8
9
SELECT * FROM t2 WHERE a = 8 FOR UPDATE;
a
8
# Switch to connection conn1
BEGIN;
INSERT INTO t2 VALUES (2);
SELECT * FROM t2 ORDER BY a;
a
2
8
9
SELECT * FROM t2 WHERE a = 9 FOR UPDATE;
a
9
SELECT * FROM t2 WHERE a = 8 FOR UPDATE;
# Switch to connection default
SELECT * FROM t2 WHERE a = 9 FOR UPDATE;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
SELECT * FROM t2 ORDER BY a;
a
1
8
9
ROLLBACK;
SELECT * FROM t2 ORDER BY a;
a
8
9
# Switch to connection conn1
UPDATE t2 SET a = 88 WHERE a = 8;
UPDATE t2 SET a = 99 WHERE a = 9;
SELECT * FROM t2 ORDER BY a;
a
2
88
99
COMMIT;
# Switch to connection default
DROP TABLE t1;
DROP TABLE t2;
