1
# Tests for various concurrency-related aspects of CREATE TABLE ... SELECT
2
# and CREATE TABLE like implementation.
4
# Note that we don't test general CREATE TABLE ... SELECT/LIKE functionality
5
# here as it is already covered by create.test. We are more interested in
8
# This test takes rather long time so let us run it only in --big-test mode
9
--source include/big_test.inc
10
# We are using some debug-only features in this test
11
--source include/have_debug.inc
12
# Some of tests below also use binlog to check that statements are
13
# executed and logged in correct order
14
--source include/have_binlog_format_mixed_or_statement.inc
16
# Create auxilliary connections
17
connect (addconroot1, localhost, root,,);
18
connect (addconroot2, localhost, root,,);
19
connect (addconroot3, localhost, root,,);
23
drop table if exists t1,t2,t3,t4,t5;
28
# Tests for concurrency problems in CREATE TABLE ... SELECT
30
# We introduce delays between various stages of table creation
31
# and check that other statements dealing with this table cannot
32
# interfere during those delays.
34
# What happens in situation when other statement messes with
35
# table to be created before it is created ?
36
# Concurrent CREATE TABLE
37
set session debug="+d,sleep_create_select_before_create";
38
--send create table t1 select 1 as i;
39
connection addconroot1;
41
--error ER_TABLE_EXISTS_ERROR
42
create table t1 (j char(5));
47
# Concurrent CREATE TABLE ... SELECT
48
--send create table t1 select 1 as i;
49
connection addconroot1;
51
--error ER_TABLE_EXISTS_ERROR
52
create table t1 select "Test" as j;
57
# Concurrent CREATE TABLE LIKE
58
create table t3 (j char(5));
59
--send create table t1 select 1 as i;
60
connection addconroot1;
62
--error ER_TABLE_EXISTS_ERROR
63
create table t1 like t3;
68
# Concurrent RENAME TABLE
69
--send create table t1 select 1 as i;
70
connection addconroot1;
72
--error ER_TABLE_EXISTS_ERROR
73
rename table t3 to t1;
78
# Concurrent ALTER TABLE RENAME
79
--send create table t1 select 1 as i;
80
connection addconroot1;
82
--error ER_TABLE_EXISTS_ERROR
83
alter table t3 rename to t1;
88
# Concurrent ALTER TABLE RENAME which also adds column
89
--send create table t1 select 1 as i;
90
connection addconroot1;
92
--error ER_TABLE_EXISTS_ERROR
93
alter table t3 rename to t1, add k int;
98
# What happens if other statement sneaks in after the table
99
# creation but before its opening ?
100
set session debug="-d,sleep_create_select_before_create:+d,sleep_create_select_before_open";
101
# Concurrent DROP TABLE
102
--send create table t1 select 1 as i;
103
connection addconroot1;
108
# Concurrent RENAME TABLE
109
--send create table t1 select 1 as i;
110
connection addconroot1;
112
rename table t1 to t2;
117
--send create table t1 select 1 as i;
118
connection addconroot1;
125
--send create table t1 select 1 as i;
126
connection addconroot1;
128
insert into t1 values (2);
133
# Concurrent CREATE TRIGGER
135
--send create table t1 select 1 as i;
136
connection addconroot1;
138
create trigger t1_bi before insert on t1 for each row set @a:=1;
143
# Okay, now the same tests for the potential gap between open and lock
144
set session debug="-d,sleep_create_select_before_open:+d,sleep_create_select_before_lock";
145
# Concurrent DROP TABLE
146
--send create table t1 select 1 as i;
147
connection addconroot1;
152
# Concurrent RENAME TABLE
153
--send create table t1 select 1 as i;
154
connection addconroot1;
156
rename table t1 to t2;
161
--send create table t1 select 1 as i;
162
connection addconroot1;
169
--send create table t1 select 1 as i;
170
connection addconroot1;
172
insert into t1 values (2);
177
# Concurrent CREATE TRIGGER
179
--send create table t1 select 1 as i;
180
connection addconroot1;
182
create trigger t1_bi before insert on t1 for each row set @a:=1;
187
# Some tests for case with existing table
188
set session debug="-d,sleep_create_select_before_lock:+d,sleep_create_select_before_check_if_exists";
189
create table t1 (i int);
190
# Concurrent DROP TABLE
191
--send create table if not exists t1 select 1 as i;
192
connection addconroot1;
197
# Concurrent CREATE TRIGGER
198
create table t1 (i int);
200
--send create table if not exists t1 select 1 as i;
201
connection addconroot1;
203
create trigger t1_bi before insert on t1 for each row set @a:=1;
209
set session debug="-d,sleep_create_select_before_check_if_exists";
212
# Test for some details of CREATE TABLE ... SELECT implementation.
214
# We check that create placeholder is handled properly if we have
215
# to reopen tables in open_tables().
216
# This test heavily relies on current implementation of name-locking/
217
# table cache so it may stop working if it changes. OTOH it such problem
218
# will serve as warning that such changes should not be done lightly.
219
create table t2 (a int);
220
create table t4 (b int);
221
connection addconroot2;
224
connection addconroot1;
225
# Create placeholder/name-lock for t3
226
--send create table t3 as select * from t4;
229
# This statement creates placeholder for t1, then opens t2,
230
# then meets name-lock for t3 and then reopens all tables
231
--send create table t1 select * from t2, t3;
233
connection addconroot2;
235
connection addconroot1;
240
show create table t1;
242
# Now similar test which proves that we really temporarily
243
# remove placeholder when we reopen tables.
244
connection addconroot2;
247
connection addconroot1;
248
# Create name-lock for t3
249
--send rename table t4 to t3;
252
# This statement creates placeholder for t1, then opens t2,
253
# then meets name-lock for t3 and then reopens all tables
254
--send create table if not exists t1 select 1 as i from t2, t3;
256
connection addconroot3;
257
# We should be able to take name-lock on table t1 as we should not have
258
# open placeholder for it at this point (otherwise it is possible to
259
# come-up with situation which will lead to deadlock, e.g. think of
260
# concurrent CREATE TABLE t1 SELECT * FROM t2 and RENAME TABLE t2 TO t1)
261
create table t5 (j int);
262
# This statement takes name-lock on t1 and therefore proves
263
# that there is no active open placeholder for it.
264
rename table t5 to t1;
265
connection addconroot2;
267
connection addconroot1;
272
show create table t1;
273
drop table t1, t2, t3;
276
# Tests for possible concurrency issues with CREATE TABLE ... LIKE
278
# Bug #18950 "create table like does not obtain LOCK_open"
279
# Bug #23667 "CREATE TABLE LIKE is not isolated from alteration by other
282
# Again the idea of this test is that we introduce artificial delays on
283
# various stages of table creation and check that concurrent statements
284
# for tables from CREATE TABLE ... LIKE are not interfering.
287
drop table if exists t1,t2;
290
# What happens if some statements sneak in right after we have
291
# opened source table ?
292
create table t1 (i int);
293
set session debug="+d,sleep_create_like_before_check_if_exists";
294
# Reset binlog to have clear start
296
--send create table t2 like t1;
297
connection addconroot1;
299
# DML on source table should be allowed to run concurrently
300
insert into t1 values (1);
301
# And DDL should wait
305
show create table t2;
307
# Let us check that statements were executed/binlogged in correct order
308
--replace_column 2 # 5 #
309
show binlog events in 'master-bin.000001' from 106;
311
# Now let us check the gap between check for target table
312
# existance and copying of .frm file.
313
create table t1 (i int);
314
set session debug="-d,sleep_create_like_before_check_if_exists:+d,sleep_create_like_before_copy";
315
# It should be impossible to create target table concurrently
316
--send create table t2 like t1;
317
connection addconroot1;
319
create table if not exists t2 (j int);
322
show create table t2;
324
# And concurrent DDL on the source table should be still disallowed
326
--send create table t2 like t1;
327
connection addconroot1;
333
--replace_column 2 # 5 #
334
show binlog events in 'master-bin.000001' from 106;
336
# And now he gap between copying of .frm file and ha_create_table() call.
337
create table t1 (i int);
338
set session debug="-d,sleep_create_like_before_copy:+d,sleep_create_like_before_ha_create";
339
# Both DML and DDL on target table should wait till operation completes
341
--send create table t2 like t1;
342
connection addconroot1;
344
insert into t2 values (1);
348
--send create table t2 like t1;
349
connection addconroot1;
354
# Concurrent DDL on the source table still waits
355
--send create table t2 like t1;
356
connection addconroot1;
362
--replace_column 2 # 5 #
363
show binlog events in 'master-bin.000001' from 106;
365
# Finally we check the gap between ha_create_table() and binlogging
366
create table t1 (i int);
367
set session debug="-d,sleep_create_like_before_ha_create:+d,sleep_create_like_before_binlogging";
369
--send create table t2 like t1;
370
connection addconroot1;
372
insert into t2 values (1);
376
--send create table t2 like t1;
377
connection addconroot1;
382
--send create table t2 like t1;
383
connection addconroot1;
389
--replace_column 2 # 5 #
390
show binlog events in 'master-bin.000001' from 106;
392
set session debug="-d,sleep_create_like_before_binlogging";