2
# Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK
3
# http://bugs.mysql.com/38231
7
SET storage_engine=InnoDB;
9
# we care only that the following SQL commands do not crash the server
11
DROP TABLE IF EXISTS bug38231;
12
CREATE TABLE bug38231 (a INT);
16
LOCK TABLE bug38231 WRITE;
19
LOCK TABLE bug38231 WRITE;
21
# When con1 does UNLOCK below this will release either con2 or con3 which are
22
# both waiting on LOCK. At the end we must first --reap and UNLOCK the
23
# connection that has been released, otherwise it will wait forever. We assume
24
# that the released connection will be the first one that has gained the LOCK,
25
# thus we force the order here - con2 does LOCK first, then con3. In other
26
# words we wait for LOCK from con2 above to be exected before doing LOCK in
29
SELECT COUNT(*) = 1 FROM information_schema.processlist
30
WHERE info = 'LOCK TABLE bug38231 WRITE';
31
# the above enables query log, re-disable it
34
LOCK TABLE bug38231 WRITE;
36
TRUNCATE TABLE bug38231;
38
# Wait for TRUNCATE and the other two LOCKs to be executed; without this,
39
# sometimes UNLOCK executes before them. We assume there are no other
40
# sessions executing at the same time with the same SQL commands.
42
SELECT COUNT(*) = 1 FROM information_schema.processlist
43
WHERE info = 'TRUNCATE TABLE bug38231';
45
SELECT COUNT(*) = 2 FROM information_schema.processlist
46
WHERE info = 'LOCK TABLE bug38231 WRITE';
47
# the above enables query log, re-disable it
49
# this crashes the server if the bug is present
60
# test that TRUNCATE works with with row-level locks
63
INSERT INTO bug38231 VALUES (1), (10), (300);
67
SELECT * FROM bug38231 FOR UPDATE;
69
TRUNCATE TABLE bug38231;