2
# Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK
3
# http://bugs.mysql.com/38231
6
-- source include/have_innodb.inc
8
SET storage_engine=InnoDB;
10
# we care only that the following SQL commands do not crash the server
14
DROP TABLE IF EXISTS bug38231;
15
CREATE TABLE bug38231 (a INT);
17
-- connect (con1,localhost,root,,)
18
-- connect (con2,localhost,root,,)
19
-- connect (con3,localhost,root,,)
23
LOCK TABLE bug38231 WRITE;
28
LOCK TABLE bug38231 WRITE;
30
# When con1 does UNLOCK below this will release either con2 or con3 which are
31
# both waiting on LOCK. At the end we must first --reap and UNLOCK the
32
# connection that has been released, otherwise it will wait forever. We assume
33
# that the released connection will be the first one that has gained the LOCK,
34
# thus we force the order here - con2 does LOCK first, then con3. In other
35
# words we wait for LOCK from con2 above to be exected before doing LOCK in
39
SELECT COUNT(*) = 1 FROM information_schema.processlist
40
WHERE info = 'LOCK TABLE bug38231 WRITE';
41
-- source include/wait_condition.inc
42
# the above enables query log, re-disable it
48
LOCK TABLE bug38231 WRITE;
52
TRUNCATE TABLE bug38231;
55
# Wait for TRUNCATE and the other two LOCKs to be executed; without this,
56
# sometimes UNLOCK executes before them. We assume there are no other
57
# sessions executing at the same time with the same SQL commands.
59
SELECT COUNT(*) = 1 FROM information_schema.processlist
60
WHERE info = 'TRUNCATE TABLE bug38231';
61
-- source include/wait_condition.inc
63
SELECT COUNT(*) = 2 FROM information_schema.processlist
64
WHERE info = 'LOCK TABLE bug38231 WRITE';
65
-- source include/wait_condition.inc
66
# the above enables query log, re-disable it
69
# this crashes the server if the bug is present
89
# test that TRUNCATE works with with row-level locks
94
INSERT INTO bug38231 VALUES (1), (10), (300);
96
-- connect (con4,localhost,root,,)
100
SELECT * FROM bug38231 FOR UPDATE;
102
-- connection default
103
TRUNCATE TABLE bug38231;
108
-- connection default