summaryrefslogtreecommitdiffstats
path: root/mysql-test/main/mdl.test
blob: 65d02d77739b29400b00fd2b49f24269f252a981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--source include/have_metadata_lock_info.inc
--source include/have_innodb.inc

--echo #
--echo # MDEV-12882 - Assertion `mdl_ticket->m_type == MDL_SHARED_UPGRADABLE ||
--echo #                         mdl_ticket->m_type == MDL_SHARED_NO_WRITE ||
--echo #                         mdl_ticket->m_type == MDL_SHARED_NO_READ_WRITE ||
--echo #                         mdl_ticket->m_type == MDL_SHARED_READ'
--echo #                         failed in MDL_context::upgrade_shared_lock
--echo #
--disable_service_connection
CREATE TABLE t1(a INT) ENGINE=InnoDB;
CREATE TABLE t3(a INT) ENGINE=myisam;
LOCK TABLES t1 WRITE CONCURRENT, t1 AS t2 READ;
SELECT LOCK_MODE, LOCK_TYPE, TABLE_SCHEMA, TABLE_NAME FROM information_schema.metadata_lock_info
WHERE TABLE_NAME NOT LIKE 'innodb_%_stats';
UNLOCK TABLES;
LOCK TABLES t1 AS t2 READ, t1 WRITE CONCURRENT;
SELECT LOCK_MODE, LOCK_TYPE, TABLE_SCHEMA, TABLE_NAME FROM information_schema.metadata_lock_info
WHERE TABLE_NAME NOT LIKE 'innodb_%_stats';
UNLOCK TABLES;
LOCK TABLES t1 WRITE CONCURRENT, t3 WRITE;
SELECT LOCK_MODE, LOCK_TYPE, TABLE_SCHEMA, TABLE_NAME FROM information_schema.metadata_lock_info
WHERE TABLE_NAME NOT LIKE 'innodb_%_stats';
UNLOCK TABLES;
LOCK TABLES t3 WRITE, t1 WRITE CONCURRENT;
SELECT LOCK_MODE, LOCK_TYPE, TABLE_SCHEMA, TABLE_NAME FROM information_schema.metadata_lock_info
WHERE TABLE_NAME NOT LIKE 'innodb_%_stats';
UNLOCK TABLES;
LOCK TABLES t1 WRITE, mysql.user WRITE;
SELECT LOCK_MODE, LOCK_TYPE, TABLE_SCHEMA, TABLE_NAME FROM information_schema.metadata_lock_info
WHERE TABLE_NAME NOT LIKE 'innodb_%_stats';
UNLOCK TABLES;
--error ER_CANT_LOCK_LOG_TABLE
LOCK TABLES mysql.general_log WRITE;
# The following may work in embedded server
--error 0,ER_DBACCESS_DENIED_ERROR
LOCK TABLES t1 WRITE,information_schema.tables READ;
UNLOCK TABLES;
DROP TABLE t1,t3;

--echo #
--echo # Check MDL locks taken for different kind of tables by open
--echo #

CREATE TABLE t1(a INT) ENGINE=InnoDB;
CREATE TABLE t3(a INT) ENGINE=myisam;
connect(purge_control,localhost,root,,);
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connect (locker,localhost,root,,);
connection default;

FLUSH TABLES WITH READ LOCK;
connection locker;
--send insert into t1 values (1)
connection default;
# Wait till above update gets blocked on a user lock.
let $wait_condition=
  select count(*) > 0 from information_schema.processlist
  where state = "Waiting for backup lock";
--source include/wait_condition.inc
connection default;
SELECT LOCK_MODE, LOCK_TYPE, TABLE_SCHEMA, TABLE_NAME FROM information_schema.metadata_lock_info
WHERE TABLE_NAME NOT LIKE 'innodb_%_stats';
unlock tables;
connection locker;
--reap
unlock tables;
connection default;

FLUSH TABLES WITH READ LOCK;
connection locker;
--send insert into t3 values (2)
connection default;
# Wait till above update gets blocked on a user lock.
let $wait_condition=
  select count(*) > 0 from information_schema.processlist
  where state = "Waiting for backup lock";
--source include/wait_condition.inc
connection default;
SELECT LOCK_MODE, LOCK_TYPE, TABLE_SCHEMA, TABLE_NAME FROM information_schema.metadata_lock_info
WHERE TABLE_NAME NOT LIKE 'innodb_%_stats';
unlock tables;
connection locker;
--reap
unlock tables;
disconnect purge_control;
connection default;

disconnect locker;
DROP TABLE t1,t3;
--enable_service_connection

--echo #
--echo # MDEV-28820 MyISAM wrong server status flags
--echo #
--disable_view_protocol
# MyISAM alone doesn't start a transaction or takes transactional MDL
create table t1 (a int);
set autocommit=0;
select @@in_transaction;
select * from t1;
select @@in_transaction;
connect foo,localhost,root;
drop table t1;
connection default;
set autocommit=1;

# MyISAM in a transaction (started by InnoDB) takes transactional MDL all right
create table t1 (a int);
create table t2 (b int) engine=innodb;
set autocommit=0;
select @@in_transaction;
select * from t2;
select @@in_transaction;
select * from t1;
connection foo;
send drop table t1;
connection default;
let $wait_condition=
  select count(*) > 0 from information_schema.processlist
  where state = "Waiting for table metadata lock";
--source include/wait_condition.inc
select * from t1;
commit;

connection foo;
reap;
disconnect foo;
connection default;
set autocommit=default;
drop table t2;
--enable_view_protocol

--echo #
--echo # End of 10.4 tests
--echo #