summaryrefslogtreecommitdiff
path: root/mysql-test/suite/innodb/t/innodb_information_schema.test
blob: 205344a1cd772885adba57d829e5b116853177c7 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# 
# Test that user data is correctly "visualized" in
# INFORMATION_SCHEMA.innodb_locks.lock_data
#

-- source include/have_innodb.inc

-- disable_query_log
-- disable_result_log

SET storage_engine=InnoDB;

-- disable_warnings
DROP TABLE IF EXISTS t_min, t_max;
-- enable_warnings

let $table_def =
(
	c01 TINYINT,
	c02 TINYINT UNSIGNED,
	c03 SMALLINT,
	c04 SMALLINT UNSIGNED,
	c05 MEDIUMINT,
	c06 MEDIUMINT UNSIGNED,
	c07 INT,
	c08 INT UNSIGNED,
	c09 BIGINT,
	c10 BIGINT UNSIGNED,
	PRIMARY KEY(c01, c02, c03, c04, c05, c06, c07, c08, c09, c10)
);

-- eval CREATE TABLE t_min $table_def;
INSERT INTO t_min VALUES
(-128, 0,
 -32768, 0,
 -8388608, 0,
 -2147483648, 0,
 -9223372036854775808, 0);

-- eval CREATE TABLE t_max $table_def;
INSERT INTO t_max VALUES
(127, 255,
 32767, 65535,
 8388607, 16777215,
 2147483647, 4294967295,
 9223372036854775807, 18446744073709551615);

CREATE TABLE ```t'\"_str` (
	c1 VARCHAR(32),
	c2 VARCHAR(32),
	c3 VARCHAR(32),
	c4 VARCHAR(32),
	c5 VARCHAR(32),
	c6 VARCHAR(32),
	c7 VARCHAR(32),
	PRIMARY KEY(c1, c2, c3, c4, c5, c6, c7)
);
INSERT INTO ```t'\"_str` VALUES
('1', 'abc', '''abc', 'abc''', 'a''bc', 'a''bc''', '''abc''''');
INSERT INTO ```t'\"_str` VALUES
('2', 'abc', '"abc', 'abc"', 'a"bc', 'a"bc"', '"abc""');
INSERT INTO ```t'\"_str` VALUES
('3', 'abc', '\\abc', 'abc\\', 'a\\bc', 'a\\bc\\', '\\abc\\\\');
INSERT INTO ```t'\"_str` VALUES
('4', 'abc', 0x00616263, 0x61626300, 0x61006263, 0x6100626300, 0x610062630000);

--source include/count_sessions.inc

-- connect (con_lock,localhost,root,,)
-- connect (con_min_trylock,localhost,root,,)
-- connect (con_max_trylock,localhost,root,,)
-- connect (con_str_insert_supremum,localhost,root,,)
-- connect (con_str_lock_row1,localhost,root,,)
-- connect (con_str_lock_row2,localhost,root,,)
-- connect (con_str_lock_row3,localhost,root,,)
-- connect (con_str_lock_row4,localhost,root,,)
-- connect (con_verify_innodb_locks,localhost,root,,)

-- connection con_lock
SET autocommit=0;
SELECT * FROM t_min FOR UPDATE;
SELECT * FROM t_max FOR UPDATE;
SELECT * FROM ```t'\"_str` FOR UPDATE;

-- connection con_min_trylock
-- send
SELECT * FROM t_min FOR UPDATE;

-- connection con_max_trylock
-- send
SELECT * FROM t_max FOR UPDATE;

-- connection con_str_insert_supremum
-- send
INSERT INTO ```t'\"_str` VALUES
('z', 'z', 'z', 'z', 'z', 'z', 'z');

-- connection con_str_lock_row1
-- send
SELECT * FROM ```t'\"_str` WHERE c1 = '1' FOR UPDATE;

-- connection con_str_lock_row2
-- send
SELECT * FROM ```t'\"_str` WHERE c1 = '2' FOR UPDATE;

-- connection con_str_lock_row3
-- send
SELECT * FROM ```t'\"_str` WHERE c1 = '3' FOR UPDATE;

-- connection con_str_lock_row4
-- send
SELECT * FROM ```t'\"_str` WHERE c1 = '4' FOR UPDATE;

-- enable_result_log
-- connection con_verify_innodb_locks
# Wait for the above queries to execute before continuing.
# Without this, it sometimes happens that the SELECT from innodb_locks
# executes before some of them, resulting in less than expected number
# of rows being selected from innodb_locks. If there is a bug and there
# are no 14 rows in innodb_locks then this test will fail with timeout.
# Notice that if we query INNODB_LOCKS more often than once per 0.1 sec
# then its contents will never change because the cache from which it is
# filled is updated only if it has not been read for 0.1 seconds. See
# CACHE_MIN_IDLE_TIME_US in trx/trx0i_s.c.
let $cnt=10;
while ($cnt)
{
    let $success=`SELECT COUNT(*) = 14 FROM INFORMATION_SCHEMA.INNODB_LOCKS`;
    if ($success)
    {
        let $cnt=0;
    }
    if (!$success)
    {
        real_sleep 0.2;
        dec $cnt;
    }
}
if (!$success)
{
    -- echo Timeout waiting for rows in INNODB_LOCKS to appear
}

SELECT lock_mode, lock_type, lock_table, lock_index, lock_rec, lock_data
FROM INFORMATION_SCHEMA.INNODB_LOCKS ORDER BY lock_data;

SELECT lock_table,COUNT(*) FROM INFORMATION_SCHEMA.INNODB_LOCKS
GROUP BY lock_table;

set @save_sql_mode = @@sql_mode;
SET SQL_MODE='ANSI_QUOTES';
SELECT lock_table,COUNT(*) FROM INFORMATION_SCHEMA.INNODB_LOCKS
GROUP BY lock_table;
SET @@sql_mode=@save_sql_mode;
-- disable_result_log

-- connection default

-- disconnect con_lock
-- disconnect con_min_trylock
-- disconnect con_max_trylock
-- disconnect con_str_insert_supremum
-- disconnect con_str_lock_row1
-- disconnect con_str_lock_row2
-- disconnect con_str_lock_row3
-- disconnect con_str_lock_row4
-- disconnect con_verify_innodb_locks

DROP TABLE t_min, t_max, ```t'\"_str`;

--source include/wait_until_count_sessions.inc

#
# Test that transaction data is correctly "visualized" in
# INFORMATION_SCHEMA.INNODB_TRX
#

-- enable_result_log
DESCRIBE INFORMATION_SCHEMA.INNODB_TRX;
-- disable_result_log

-- disable_warnings
DROP TABLE IF EXISTS t1;
-- enable_warnings

CREATE TABLE t1 (
	c01 INT,
	c02 INT,
	PRIMARY KEY (c01)
) ENGINE = InnoDB;

INSERT INTO t1 VALUES
(1,2),(2,4),(3,6),(4,8);

CREATE TABLE t2 (
	c01 INT,
	c02 INT,
	PRIMARY KEY (c01),
	FOREIGN KEY fk1 (c02) REFERENCES t1 (c01)
) ENGINE = InnoDB;

INSERT INTO t2 VALUES
(1,1),(2,2),(3,3);

-- connect (con_trx,localhost,root,,)
-- connect (con_verify_innodb_trx,localhost,root,,)

-- connection con_trx
SET autocommit=0;
INSERT INTO t1 VALUES (5,10);
SELECT * FROM t1 FOR UPDATE;

let $wait_condition=
  SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.INNODB_TRX;
--source include/wait_condition.inc
-- disable_query_log

-- connection con_verify_innodb_trx
-- enable_result_log
SELECT trx_state, trx_weight, trx_tables_in_use, trx_tables_locked,
trx_rows_locked, trx_rows_modified, trx_concurrency_tickets,
trx_isolation_level, trx_unique_checks, trx_foreign_key_checks
FROM INFORMATION_SCHEMA.INNODB_TRX;

-- connection con_trx
-- disable_result_log
ROLLBACK;
SET FOREIGN_KEY_CHECKS = 0;
SET UNIQUE_CHECKS = 0;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN;
INSERT INTO t1 VALUES (6,12);

let $wait_condition=
  SELECT trx_unique_checks = 0 FROM INFORMATION_SCHEMA.INNODB_TRX;
--source include/wait_condition.inc
-- disable_query_log

-- connection con_verify_innodb_trx
-- enable_result_log
SELECT trx_isolation_level, trx_unique_checks, trx_foreign_key_checks
FROM INFORMATION_SCHEMA.INNODB_TRX;

-- disable_result_log
-- connection con_trx
ROLLBACK;
SET FOREIGN_KEY_CHECKS = 1;
SET UNIQUE_CHECKS = 1;
BEGIN;
-- error 1452
INSERT INTO t2 VALUES (4,10);

let $wait_condition=
  SELECT trx_unique_checks  = 1 FROM INFORMATION_SCHEMA.INNODB_TRX;
--source include/wait_condition.inc
-- disable_query_log

-- enable_result_log
-- connection con_verify_innodb_trx
SELECT trx_state, trx_isolation_level, trx_last_foreign_key_error
FROM INFORMATION_SCHEMA.INNODB_TRX;
-- disable_result_log

-- connection default

-- disconnect con_trx
-- disconnect con_verify_innodb_trx

DROP TABLE t2;
DROP TABLE t1;