~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Check some special create statements.
3
#
4
5
--disable_warnings
6
drop table if exists t1,t2,t3,t4,t5;
7
drop database if exists mysqltest;
8
--enable_warnings
9
10
create table t1 (b char(0));
11
insert into t1 values (""),(null);
12
select * from t1;
13
drop table if exists t1;
14
15
create table t1 (b char(0) not null);
16
create table if not exists t1 (b char(0) not null);
722.2.15 by Monty Taylor
Fixed create.test.
17
--error 1048
1 by brian
clean slate
18
insert into t1 values (""),(null);
19
select * from t1;
20
drop table t1;
21
22
create table t1 (a int not null auto_increment,primary key (a)) engine=heap;
23
drop table t1;
24
25
#
26
# Test of some CREATE TABLE'S that should fail
27
#
28
29
--error 1146
30
create table t2 engine=heap select * from t1;
31
--error 1146
32
create table t2 select auto+1 from t1;
33
drop table if exists t1,t2;
34
--error 1167
35
create table t1 (b char(0) not null, index(b));
36
--error 1163
37
create table t1 (a int not null,b text) engine=heap;
38
drop table if exists t1;
39
40
--error 1075
722.2.15 by Monty Taylor
Fixed create.test.
41
create table t1 (ordid int not null auto_increment, ord  varchar(50) not null, primary key (ord,ordid)) engine=heap;
1 by brian
clean slate
42
43
-- error 1049
44
create table not_existing_database.test (a int);
45
create table `a/a` (a int);
46
show create table `a/a`;
47
create table t1 like `a/a`;
48
drop table `a/a`;
49
drop table `t1`;
50
--error 1103
51
create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int);
52
--error 1059
53
create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int);
54
55
#
56
# Some wrong defaults, so these creates should fail too (Bug #5902)
57
#
58
--error 1067
59
create table t1 (a datetime default now());
60
--error 1294
61
create table t1 (a datetime on update now());
62
--error 1067
63
create table t1 (a int default 100 auto_increment);
722.2.15 by Monty Taylor
Fixed create.test.
64
# TODO: Should this really fail? What's wrong with default 1000 ???
65
#--error 1067
66
#create table t1 (a int default 1000);
1 by brian
clean slate
67
--error 1067
68
create table t1 (a varchar(5) default 'abcdef');
69
70
create table t1 (a varchar(5) default 'abcde');
71
insert into t1 values();
72
select * from t1;
73
--error 1067
74
alter table t1 alter column a set default 'abcdef';
75
drop table t1;
76
77
#
78
# test of dummy table names
79
#
80
81
create table 1ea10 (1a20 int,1e int);
82
insert into 1ea10 values(1,1);
83
select 1ea10.1a20,1e+ 1e+10 from 1ea10;
84
drop table 1ea10;
85
create table t1 (t1.index int);
86
drop table t1;
87
# Test that we get warning for this
88
drop database if exists mysqltest;
89
create database mysqltest;
90
create table mysqltest.$test1 (a$1 int, $b int, c$ int);
91
insert into mysqltest.$test1 values (1,2,3);
92
select a$1, $b, c$ from mysqltest.$test1;
93
create table mysqltest.test2$ (a int);
94
drop table mysqltest.test2$;
95
drop database mysqltest;
96
97
--error 1103
98
create table `` (a int);
99
--error 1103
100
drop table if exists ``;
101
--error 1166
102
create table t1 (`` int);
103
--error 1280
104
create table t1 (i int, index `` (i)); 
105
106
#
107
# Test of CREATE ... SELECT with indexes
108
#
109
110
create table t1 (a int auto_increment not null primary key, B CHAR(20));
111
insert into t1 (b) values ("hello"),("my"),("world");
112
create table t2 (key (b)) select * from t1;
113
explain select * from t2 where b="world";
114
select * from t2 where b="world";
115
drop table t1,t2;
116
117
#
118
# Test types after CREATE ... SELECT
119
#
120
121
create table t1(x varchar(50) );
122
create table t2 select x from t1 where 1=2;
123
describe t1;
124
describe t2;
125
drop table t2;
126
create table t2 select now() as a , curtime() as b, curdate() as c , 1+1 as d , 1.0 + 1 as e , 33333333333333333 + 3 as f;
127
describe t2;
128
drop table t2;
129
create table t2 select CAST("2001-12-29" AS DATE) as d, CAST("20:45:11" AS TIME) as t, CAST("2001-12-29  20:45:11" AS DATETIME) as dt;
130
describe t2;
131
drop table t1,t2;
132
133
#
134
# Test of CREATE ... SELECT with duplicate fields
135
#
136
396 by Brian Aker
Cleanup tiny and small int.
137
create table t1 (a int);
1 by brian
clean slate
138
create table t2 (a int) select * from t1;                        
139
describe t1;
140
describe t2;
141
drop table if exists t2;
142
--error 1060
143
create table t2 (a int, a float) select * from t1;               
144
drop table if exists t2;
145
--error 1060
146
create table t2 (a int) select a as b, a+1 as b from t1;         
147
drop table if exists t2;
148
--error 1060
149
create table t2 (b int) select a as b, a+1 as b from t1;         
150
drop table if exists t1,t2;
151
152
#
153
# Test CREATE ... SELECT when insert fails
154
#
155
156
CREATE TABLE t1 (a int not null);
157
INSERT INTO t1 values (1),(2),(1);
158
--error ER_DUP_ENTRY
159
CREATE TABLE t2 (primary key(a)) SELECT * FROM t1;
160
--error 1146
161
SELECT * from t2;
162
DROP TABLE t1;
163
DROP TABLE IF EXISTS t2;
164
165
#
166
# Test of primary key with 32 index
167
#
168
169
create table t1 (a int not null, b int, primary key(a), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b));
170
show create table t1;
171
drop table t1;
172
create table t1 select if(1,'1','0'), month("2002-08-02");
173
drop table t1;
174
create table t1 select if('2002'='2002','Y','N');
175
select * from t1;
176
drop table if exists t1;
177
178
#
179
# Test default table type
180
#
181
SET SESSION storage_engine="heap";
182
SELECT @@storage_engine;
183
CREATE TABLE t1 (a int not null);
184
show create table t1;
185
drop table t1;
186
--error 1286
187
SET SESSION storage_engine="gemini";
188
SELECT @@storage_engine;
189
CREATE TABLE t1 (a int not null);
190
show create table t1;
191
SET SESSION storage_engine=default;
192
drop table t1;
193
194
195
#
196
# ISO requires that primary keys are implicitly NOT NULL
197
#
198
create table t1 ( k1 varchar(2), k2 int, primary key(k1,k2));
199
insert into t1 values ("a", 1), ("b", 2);
200
--error 1048
201
insert into t1 values ("c", NULL);
202
--error 1048
203
insert into t1 values (NULL, 3);
204
--error 1048
205
insert into t1 values (NULL, NULL);
206
drop table t1;
207
208
#
209
# Bug # 801
210
#
211
212
create table t1 select x'4132';
213
drop table t1;
214
215
#
216
# bug #1434
217
#
218
219
create table t1 select 1,2,3;
220
create table if not exists t1 select 1,2;
221
create table if not exists t1 select 1,2,3,4;
222
create table if not exists t1 select 1;
223
select * from t1;
224
drop table t1;
225
226
#
227
# Test create table if not exists with duplicate key error
228
#
229
230
flush status;
231
create table t1 (a int not null, b int, primary key (a));
232
insert into t1 values (1,1);
722.2.15 by Monty Taylor
Fixed create.test.
233
# TODO: BUG here, this is filling in right to left for some reason
234
#create table if not exists t1 select 2;
1 by brian
clean slate
235
select * from t1;
236
create table if not exists t1 select 3 as 'a',4 as 'b';
237
--error ER_DUP_ENTRY
238
create table if not exists t1 select 3 as 'a',3 as 'b';
239
show warnings;
240
show status like "Opened_tables";
241
select * from t1;
242
drop table t1;
243
244
#
245
# Test for Bug #2985 
246
#   "Table truncated when creating another table name with Spaces"
247
#
248
249
--error 1103
250
create table `t1 `(a int);
251
--error 1102
252
create database `db1 `;
253
--error 1166
254
create table t1(`a ` int);
255
256
#
257
# Test for Bug #3481 
258
#   "Parser permits multiple commas without syntax error"
259
#
260
261
--error 1064
262
create table t1 (a int,);
263
--error 1064
264
create table t1 (a int,,b int);
265
--error 1064
266
create table t1 (,b int);
267
268
#
269
# Test create with foreign keys
270
#
271
272
create table t1 (a int, key(a));
273
create table t2 (b int, foreign key(b) references t1(a), key(b));
722.2.15 by Monty Taylor
Fixed create.test.
274
--error 1217
1 by brian
clean slate
275
drop table if exists t1,t2;
722.2.15 by Monty Taylor
Fixed create.test.
276
drop table if exists t2,t1;
1 by brian
clean slate
277
278
#
279
# Test for CREATE TABLE .. LIKE ..
280
#
281
282
create table t1(id int not null, name char(20));
283
insert into t1 values(10,'mysql'),(20,'monty- the creator');
284
create table t2(id int not null);
285
insert into t2 values(10),(20);
286
create table t3 like t1;
287
show create table t3;
288
select * from t3;
289
# Disable PS becasue of @@warning_count
290
create table if not exists t3 like t1;
291
--disable_ps_protocol
292
select @@warning_count;
293
--enable_ps_protocol
294
create temporary table t3 like t2;
295
show create table t3;
296
select * from t3;
297
drop table t3;
298
show create table t3;
299
select * from t3;
300
drop table t2, t3;
301
create database mysqltest;
302
create table mysqltest.t3 like t1;
303
create temporary table t3 like mysqltest.t3;
304
show create table t3;
305
create table t2 like t3;
306
show create table t2;
307
select * from t2;
308
create table t3 like t1;
309
--error 1050
310
create table t3 like mysqltest.t3;
311
--error 1049
312
create table non_existing_database.t1 like t1;
313
--error ER_NO_SUCH_TABLE
314
create table t3 like non_existing_table;
315
--error 1050
316
create temporary table t3 like t1;
317
drop table t1, t2, t3;
318
drop table t3;
319
drop database mysqltest;
320
321
#
322
# Test default table type
323
#
324
SET SESSION storage_engine="heap";
325
SELECT @@storage_engine;
326
CREATE TABLE t1 (a int not null);
327
show create table t1;
328
drop table t1;
329
--error 1286
330
SET SESSION storage_engine="gemini";
331
SELECT @@storage_engine;
332
CREATE TABLE t1 (a int not null);
333
show create table t1;
334
SET SESSION storage_engine=default;
335
drop table t1;
336
337
#
338
# Test types of data for create select with functions
339
#
340
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
341
create table t1(a int,b int,c int,d date,e char,f datetime,g time,h blob);
1 by brian
clean slate
342
insert into t1(a)values(1);
343
insert into t1(a,b,c,d,e,f,g,h)
344
values(2,-2,2,'1825-12-14','a','2003-1-1 3:2:1','4:3:2','binary data');
345
select * from t1;
346
select a, 
722.2.15 by Monty Taylor
Fixed create.test.
347
    ifnull(b,-7) as b, 
348
    ifnull(c,7) as c, 
1 by brian
clean slate
349
    ifnull(d,cast('2000-01-01' as date)) as d, 
350
    ifnull(e,cast('b' as char)) as e,
351
    ifnull(f,cast('2000-01-01' as datetime)) as f, 
352
    ifnull(g,cast('5:4:3' as time)) as g,
353
    ifnull(h,cast('yet another binary data' as binary)) as h,
354
    addtime(cast('1:0:0' as time),cast('1:0:0' as time)) as dd 
355
from t1;
356
357
create table t2
358
select
359
    a, 
722.2.15 by Monty Taylor
Fixed create.test.
360
    ifnull(b,-7)                            as b,
361
    ifnull(c,7)                             as c,
1 by brian
clean slate
362
    ifnull(d,cast('2000-01-01'              as date))     as d,
363
    ifnull(e,cast('b'                       as char))     as e,
364
    ifnull(f,cast('2000-01-01'              as datetime)) as f,
365
    ifnull(g,cast('5:4:3'                   as time))     as g,
366
    ifnull(h,cast('yet another binary data' as binary))   as h,
367
    addtime(cast('1:0:0' as time),cast('1:0:0' as time))  as dd
368
from t1;
369
explain t2;
370
select * from t2;
371
drop table t1, t2;
372
722.2.15 by Monty Taylor
Fixed create.test.
373
create table t1 (a int, b int, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), j date, k timestamp, l datetime, m enum('a','b'), o char(10));
374
create table t2 select ifnull(a,a), ifnull(b,b), ifnull(d,d), ifnull(e,e), ifnull(f,f), ifnull(g,g), ifnull(h,h), ifnull(j,j), ifnull(k,k), ifnull(l,l), ifnull(m,m), ifnull(o,o) from t1;
1 by brian
clean slate
375
show create table t2;
376
drop table t1,t2;
377
378
#
379
# Test of default()
380
#
381
create table t1(str varchar(10) default 'def',strnull varchar(10),intg int default '10',rel double default '3.14');
382
insert into t1 values ('','',0,0.0);
383
describe t1;
384
create table t2 select default(str) as str, default(strnull) as strnull, default(intg) as intg, default(rel) as rel from t1;
385
describe t2;
386
drop table t1, t2;
387
388
#
389
# Bug #2075
390
#
391
396 by Brian Aker
Cleanup tiny and small int.
392
create table t1(name varchar(10), age int default -1);
1 by brian
clean slate
393
describe t1;
396 by Brian Aker
Cleanup tiny and small int.
394
create table t2(name varchar(10), age int default - 1);
1 by brian
clean slate
395
describe t2;
396
drop table t1, t2;
397
398
#
399
# test for bug #1427 "enum allows duplicate values in the list"
400
#
401
722.2.15 by Monty Taylor
Fixed create.test.
402
create table t1(cenum enum('a'));
403
--error 1291
404
create table t2(cenum enum('a','a'));
405
--error 1291
406
create table t3(cenum enum('a','A','a','c','c'));
407
drop table t1;
1 by brian
clean slate
408
409
#
410
# Bug #1209
411
#
412
413
create database mysqltest;
414
use mysqltest;
415
select database();
416
drop database mysqltest;
417
select database();
418
use test;
419
420
#
421
# Test for Bug 856 'Naming a key "Primary" causes trouble'
422
#
423
722.2.15 by Monty Taylor
Fixed create.test.
424
## TODO: Is this really a bug? It works in Drizzle. Should it?
425
#--error 1280
426
#create table t1 (a int, index `primary` (a));
427
#--error 1280
428
#create table t1 (a int, index `PRIMARY` (a));
429
#
430
#create table t1 (`primary` int, index(`primary`));
431
#show create table t1;
432
#create table t2 (`PRIMARY` int, index(`PRIMARY`));
433
#show create table t2;
434
#
435
#create table t3 (a int);
436
#--error 1280
437
#alter table t3 add index `primary` (a);
438
#--error 1280
439
#alter table t3 add index `PRIMARY` (a);
440
#
441
#create table t4 (`primary` int);
442
#alter table t4 add index(`primary`);
443
#show create table t4;
444
#create table t5 (`PRIMARY` int);
445
#alter table t5 add index(`PRIMARY`);
446
#show create table t5;
447
#
448
#drop table t1, t2, t3, t4, t5;
1 by brian
clean slate
449
450
#
451
# bug #3266 TEXT in CREATE TABLE SELECT
452
#
453
454
CREATE TABLE t1(id varchar(10) NOT NULL PRIMARY KEY, dsc longtext);
455
INSERT INTO t1 VALUES ('5000000001', NULL),('5000000003', 'Test'),('5000000004', NULL);
456
CREATE TABLE t2(id varchar(15) NOT NULL, proc varchar(100) NOT NULL, runID varchar(16) NOT NULL, start datetime NOT NULL, PRIMARY KEY  (id,proc,runID,start));
457
458
INSERT INTO t2 VALUES ('5000000001', 'proc01', '20031029090650', '2003-10-29 13:38:40'),('5000000001', 'proc02', '20031029090650', '2003-10-29 13:38:51'),('5000000001', 'proc03', '20031029090650', '2003-10-29 13:38:11'),('5000000002', 'proc09', '20031024013310', '2003-10-24 01:33:11'),('5000000002', 'proc09', '20031024153537', '2003-10-24 15:36:04'),('5000000004', 'proc01', '20031024013641', '2003-10-24 01:37:29'),('5000000004', 'proc02', '20031024013641', '2003-10-24 01:37:39');
459
460
CREATE TABLE t3  SELECT t1.dsc,COUNT(DISTINCT t2.id) AS countOfRuns  FROM t1 LEFT JOIN t2 ON (t1.id=t2.id) GROUP BY t1.id;
461
SELECT * FROM t3;
462
drop table t1, t2, t3;
463
464
465
#
466
# Bug#10224 - ANALYZE TABLE crashing with simultaneous
467
# CREATE ... SELECT statement.
468
# This tests two additional possible errors and a hang if 
469
# an improper fix is present.
470
#
471
create table t1 (a int);
722.2.15 by Monty Taylor
Fixed create.test.
472
## TODO: Should this statement fail?
473
#--error 1093
1 by brian
clean slate
474
create table t1 select * from t1;
722.2.15 by Monty Taylor
Fixed create.test.
475
## TODO: Huh? --error ER_WRONG_OBJECT
476
#create table t2 union = (t1) select * from t1;
1 by brian
clean slate
477
flush tables with read lock;
478
unlock tables;
479
drop table t1;
480
481
#
482
# Bug#10413: Invalid column name is not rejected
483
#
484
--error 1103
485
create table t1(column.name int);
486
--error 1103
487
create table t1(test.column.name int);
488
--error 1102
489
create table t1(xyz.t1.name int);
490
create table t1(t1.name int);
491
create table t2(test.t2.name int);
492
drop table t1,t2;
493
494
#
495
# Bug #12537: UNION produces longtext instead of varchar
496
#
722.2.15 by Monty Taylor
Fixed create.test.
497
CREATE TABLE t1 (f1 VARCHAR(255));
1 by brian
clean slate
498
CREATE TABLE t2 AS SELECT LEFT(f1,171) AS f2 FROM t1 UNION SELECT LEFT(f1,171) AS f2 FROM t1;
499
DESC t2;
500
DROP TABLE t1,t2;
501
502
#
503
# Bug#12913 Simple SQL can crash server or connection
504
#
505
CREATE TABLE t12913 (f1 ENUM ('a','b')) AS SELECT 'a' AS f1;
506
SELECT * FROM t12913;
507
DROP TABLE t12913;
508
509
#
510
# Bug#11028: Crash on create table like
511
#
512
create database mysqltest;
513
use mysqltest;
514
drop database mysqltest;
515
--error ER_NO_DB_ERROR 
516
create table test.t1 like x;
517
--disable_warnings
518
drop table if exists test.t1;
519
--enable_warnings
520
521
# Bug #6008 MySQL does not create warnings when
522
# creating database and using IF NOT EXISTS
523
#
524
create database mysqltest;
722.2.15 by Monty Taylor
Fixed create.test.
525
create database if not exists mysqltest;
1 by brian
clean slate
526
show create database mysqltest;
527
drop database mysqltest;
528
use test;
529
create table t1 (a int);
530
create table if not exists t1 (a int);
531
drop table t1;
532
533
# BUG#14139
534
create table t1 (
722.2.15 by Monty Taylor
Fixed create.test.
535
  a varchar(112) collate utf8_bin not null,
1 by brian
clean slate
536
  primary key (a)
537
) select 'test' as a ;
538
#--warning 1364
539
show create table t1;
540
drop table t1;
541
542
#
543
# BUG#14480: assert failure in CREATE ... SELECT because of wrong
544
#            calculation of number of NULLs.
545
#
546
CREATE TABLE t2 (
722.2.15 by Monty Taylor
Fixed create.test.
547
  a int default NULL
1 by brian
clean slate
548
);
549
insert into t2 values(111);
550
551
#--warning 1364
552
create table t1 ( 
722.2.15 by Monty Taylor
Fixed create.test.
553
  a varchar(12) collate utf8_bin not null, 
1 by brian
clean slate
554
  b int not null, primary key (a)
555
) select a, 1 as b from t2 ;
556
show create table t1;
557
drop table t1;
558
722.2.15 by Monty Taylor
Fixed create.test.
559
--error 1364
1 by brian
clean slate
560
create table t1 ( 
722.2.15 by Monty Taylor
Fixed create.test.
561
  a varchar(12) collate utf8_bin not null, 
1 by brian
clean slate
562
  b int not null, primary key (a)
563
) select a, 1 as c from t2 ;
564
565
create table t1 ( 
722.2.15 by Monty Taylor
Fixed create.test.
566
  a varchar(12) collate utf8_bin not null, 
1 by brian
clean slate
567
  b int null, primary key (a)
568
) select a, 1 as c from t2 ;
569
show create table t1;
570
drop table t1;
571
572
create table t1 ( 
722.2.15 by Monty Taylor
Fixed create.test.
573
  a varchar(12) collate utf8_bin not null,
1 by brian
clean slate
574
  b int not null, primary key (a)
575
) select 'a' as a , 1 as b from t2 ;
576
show create table t1;
577
drop table t1;
578
579
create table t1 ( 
722.2.15 by Monty Taylor
Fixed create.test.
580
  a varchar(12) collate utf8_bin,
1 by brian
clean slate
581
  b int not null, primary key (a)
582
) select 'a' as a , 1 as b from t2 ;
583
show create table t1;
584
drop table t1, t2;
585
586
create table t1 ( 
587
  a1 int not null,
588
  a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int
589
);
590
insert into t1 values (1,1,1, 1,1,1, 1,1,1);
591
592
#--warning 1364
593
create table t2 ( 
722.2.15 by Monty Taylor
Fixed create.test.
594
  a1 varchar(12) collate utf8_bin not null,
1 by brian
clean slate
595
  a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int,
596
  primary key (a1)
597
) select a1,a2,a3,a4,a5,a6,a7,a8,a9 from t1 ;
598
drop table t2;
599
600
#--warning 1364
601
create table t2 ( 
722.2.15 by Monty Taylor
Fixed create.test.
602
  a1 varchar(12) collate utf8_bin,
1 by brian
clean slate
603
  a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int
604
) select a1,a2,a3,a4,a5,a6,a7,a8,a9 from t1;
605
606
drop table t1, t2;
607
#--warning 1364
608
create table t1 ( 
609
  a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int
610
);
611
insert into t1 values (1,1,1, 1,1,1, 1,1,1);
612
613
#--warning 1364
614
create table t2 ( 
722.2.15 by Monty Taylor
Fixed create.test.
615
  a1 varchar(12) collate utf8_bin not null,
1 by brian
clean slate
616
  a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int,
617
  primary key (a1)
618
) select a1,a2,a3,a4,a5,a6,a7,a8,a9 from t1 ;
619
620
# Test the default value
621
drop table t2;
622
623
create table t2 ( a int default 3, b int default 3)
624
  select a1,a2 from t1;
625
show create table t2;
626
627
drop table t1, t2;
628
629
630
#
631
# Bug #14155: Maximum value of MAX_ROWS handled incorrectly on 64-bit
632
# platforms
633
#
634
create table t1 (i int) engine=myisam max_rows=100000000000;
635
show create table t1;
636
alter table t1 max_rows=100;
637
show create table t1;
638
alter table t1 max_rows=100000000000;
639
show create table t1;
640
drop table t1;
641
642
643
#
644
# Tests for errors happening at various stages of CREATE TABLES ... SELECT
645
#
646
# (Also checks that it behaves atomically in the sense that in case
647
#  of error it is automatically dropped if it has not existed before.)
648
#
649
# Error during open_and_lock_tables() of tables
650
--error ER_NO_SUCH_TABLE
651
create table t1 select * from t2;
652
# Rather special error which also caught during open tables pahse
653
--error ER_UPDATE_TABLE_USED
654
create table t1 select * from t1;
655
# Error which happens before select_create::prepare()
656
--error ER_CANT_AGGREGATE_2COLLATIONS
722.2.15 by Monty Taylor
Fixed create.test.
657
create table t1 select coalesce('a' collate utf8_swedish_ci,'b' collate utf8_bin);
1 by brian
clean slate
658
# Error during table creation
659
--error ER_KEY_COLUMN_DOES_NOT_EXITS
660
create table t1 (primary key(a)) select "b" as b;
661
# Error in select_create::prepare() which is not related to table creation
722.2.15 by Monty Taylor
Fixed create.test.
662
# TODO: This really should be failing...
663
# create table t1 (a int);
664
# --error ER_WRONG_VALUE_COUNT_ON_ROW
665
# create table if not exists t1 select 1 as a, 2 as b;
666
# drop table t1;
1 by brian
clean slate
667
# Finally error which happens during insert
668
--error ER_DUP_ENTRY
669
create table t1 (primary key (a)) (select 1 as a) union all (select 1 as a);
670
# What happens if table already exists ?
671
create table t1 (i int);
722.2.15 by Monty Taylor
Fixed create.test.
672
# TODO: BUG lp:311045
673
#--error ER_TABLE_EXISTS_ERROR
674
#create table t1 select 1 as i;
1 by brian
clean slate
675
create table if not exists t1 select 1 as i;
676
select * from t1;
722.2.15 by Monty Taylor
Fixed create.test.
677
drop table t1;
1 by brian
clean slate
678
# Error before select_create::prepare()
679
--error ER_CANT_AGGREGATE_2COLLATIONS
722.2.15 by Monty Taylor
Fixed create.test.
680
create table t1 select coalesce('a' collate utf8_swedish_ci,'b' collate utf8_bin);
1 by brian
clean slate
681
# Error which happens during insertion of rows
722.2.15 by Monty Taylor
Fixed create.test.
682
# TODO: Bug lp:311072
683
# create table t1 (i int);
684
# alter table t1 add primary key (i);
685
# --error ER_DUP_ENTRY
686
# create table if not exists t1 (select 2 as i) union all (select 2 as i);
687
# select * from t1;
688
# drop table t1;
1 by brian
clean slate
689
690
691
# Base vs temporary tables dillema (a.k.a. bug#24508 "Inconsistent
692
# results of CREATE TABLE ... SELECT when temporary table exists").
693
# In this situation we either have to create non-temporary table and
694
# insert data in it or insert data in temporary table without creation
695
# of permanent table. Since currently temporary tables always shadow
696
# permanent tables we adopt second approach.
697
create temporary table t1 (j int);
698
create table if not exists t1 select 1;
699
select * from t1;
700
drop temporary table t1;
701
--error ER_NO_SUCH_TABLE
702
select * from t1;
703
--error ER_BAD_TABLE_ERROR
704
drop table t1;
705
706
707
#
708
# CREATE TABLE ... SELECT and LOCK TABLES
709
#
710
# There is little sense in using CREATE TABLE ... SELECT under
711
# LOCK TABLES as it mostly does not work. At least we check that
712
# the server doesn't crash, hang and produces sensible errors.
713
# Includes test for bug #20662 "Infinite loop in CREATE TABLE
714
# IF NOT EXISTS ... SELECT with locked tables".
715
create table t1 (i int);
716
insert into t1 values (1), (2);
717
lock tables t1 read;
718
--error ER_TABLE_NOT_LOCKED
719
create table t2 select * from t1;
720
--error ER_TABLE_NOT_LOCKED
721
create table if not exists t2 select * from t1;
722
unlock tables;
723
create table t2 (j int);
724
lock tables t1 read;
725
--error ER_TABLE_NOT_LOCKED
726
create table t2 select * from t1;
727
# This should not be ever allowed as it will undermine
728
# lock-all-at-once approach
729
--error ER_TABLE_NOT_LOCKED
730
create table if not exists t2 select * from t1;
731
unlock tables;
732
lock table t1 read, t2 read;
733
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
734
create table t2 select * from t1;
735
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
736
create table if not exists t2 select * from t1;
737
unlock tables;
738
lock table t1 read, t2 write;
739
--error ER_TABLE_EXISTS_ERROR
740
create table t2 select * from t1;
741
# This is the only case which really works.
742
create table if not exists t2 select * from t1;
743
select * from t1;
744
unlock tables;
745
drop table t2;
746
747
# OTOH CREATE TEMPORARY TABLE ... SELECT should work
748
# well under LOCK TABLES.
749
lock tables t1 read;
750
create temporary table t2 select * from t1;
751
create temporary table if not exists t2 select * from t1;
752
select * from t2;
753
unlock tables;
754
drop table t1, t2;
755
756
757
#
758
# Bug#21772: can not name a column 'upgrade' when create a table
759
#
760
create table t1 (upgrade int);
761
drop table t1;
762
763
764
#
765
# Bug #26642: create index corrupts table definition in .frm
766
#
767
# Problem with creating keys with maximum key-parts and maximum name length
768
# This test is made for a mysql server supporting names up to 64 bytes
769
# and a maximum of 16 key segements per Key
770
#
771
772
create table t1 (
773
  c1 int, c2 int, c3 int, c4 int, c5 int, c6 int, c7 int, c8 int,
774
  c9 int, c10 int, c11 int, c12 int, c13 int, c14 int, c15 int, c16 int,
775
776
 key a001_long_123456789_123456789_123456789_123456789_123456789_1234 (
777
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
778
 key a002_long_123456789_123456789_123456789_123456789_123456789_1234 (
779
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
780
 key a003_long_123456789_123456789_123456789_123456789_123456789_1234 (
781
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
782
 key a004_long_123456789_123456789_123456789_123456789_123456789_1234 (
783
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
784
 key a005_long_123456789_123456789_123456789_123456789_123456789_1234 (
785
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
786
 key a006_long_123456789_123456789_123456789_123456789_123456789_1234 (
787
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
788
 key a007_long_123456789_123456789_123456789_123456789_123456789_1234 (
789
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
790
 key a008_long_123456789_123456789_123456789_123456789_123456789_1234 (
791
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
792
 key a009_long_123456789_123456789_123456789_123456789_123456789_1234 (
793
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
794
795
 key a010_long_123456789_123456789_123456789_123456789_123456789_1234 (
796
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
797
 key a011_long_123456789_123456789_123456789_123456789_123456789_1234 (
798
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
799
 key a012_long_123456789_123456789_123456789_123456789_123456789_1234 (
800
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
801
 key a013_long_123456789_123456789_123456789_123456789_123456789_1234 (
802
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
803
 key a014_long_123456789_123456789_123456789_123456789_123456789_1234 (
804
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
805
 key a015_long_123456789_123456789_123456789_123456789_123456789_1234 (
806
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
807
 key a016_long_123456789_123456789_123456789_123456789_123456789_1234 (
808
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
809
 key a017_long_123456789_123456789_123456789_123456789_123456789_1234 (
810
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
811
 key a018_long_123456789_123456789_123456789_123456789_123456789_1234 (
812
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
813
 key a019_long_123456789_123456789_123456789_123456789_123456789_1234 (
814
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
815
816
 key a020_long_123456789_123456789_123456789_123456789_123456789_1234 (
817
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
818
 key a021_long_123456789_123456789_123456789_123456789_123456789_1234 (
819
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
820
 key a022_long_123456789_123456789_123456789_123456789_123456789_1234 (
821
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
822
 key a023_long_123456789_123456789_123456789_123456789_123456789_1234 (
823
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
824
 key a024_long_123456789_123456789_123456789_123456789_123456789_1234 (
825
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
826
 key a025_long_123456789_123456789_123456789_123456789_123456789_1234 (
827
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
828
 key a026_long_123456789_123456789_123456789_123456789_123456789_1234 (
829
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
830
 key a027_long_123456789_123456789_123456789_123456789_123456789_1234 (
831
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
832
 key a028_long_123456789_123456789_123456789_123456789_123456789_1234 (
833
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
834
 key a029_long_123456789_123456789_123456789_123456789_123456789_1234 (
835
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
836
837
 key a030_long_123456789_123456789_123456789_123456789_123456789_1234 (
838
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
839
 key a031_long_123456789_123456789_123456789_123456789_123456789_1234 (
840
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
841
 key a032_long_123456789_123456789_123456789_123456789_123456789_1234 (
842
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
843
 key a033_long_123456789_123456789_123456789_123456789_123456789_1234 (
844
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
845
 key a034_long_123456789_123456789_123456789_123456789_123456789_1234 (
846
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
847
 key a035_long_123456789_123456789_123456789_123456789_123456789_1234 (
848
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
849
 key a036_long_123456789_123456789_123456789_123456789_123456789_1234 (
850
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
851
 key a037_long_123456789_123456789_123456789_123456789_123456789_1234 (
852
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
853
 key a038_long_123456789_123456789_123456789_123456789_123456789_1234 (
854
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
855
 key a039_long_123456789_123456789_123456789_123456789_123456789_1234 (
856
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
857
858
 key a040_long_123456789_123456789_123456789_123456789_123456789_1234 (
859
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
860
 key a041_long_123456789_123456789_123456789_123456789_123456789_1234 (
861
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
862
 key a042_long_123456789_123456789_123456789_123456789_123456789_1234 (
863
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
864
 key a043_long_123456789_123456789_123456789_123456789_123456789_1234 (
865
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
866
 key a044_long_123456789_123456789_123456789_123456789_123456789_1234 (
867
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
868
 key a045_long_123456789_123456789_123456789_123456789_123456789_1234 (
869
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
870
 key a046_long_123456789_123456789_123456789_123456789_123456789_1234 (
871
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
872
 key a047_long_123456789_123456789_123456789_123456789_123456789_1234 (
873
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
874
 key a048_long_123456789_123456789_123456789_123456789_123456789_1234 (
875
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
876
 key a049_long_123456789_123456789_123456789_123456789_123456789_1234 (
877
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
878
879
 key a050_long_123456789_123456789_123456789_123456789_123456789_1234 (
880
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
881
 key a051_long_123456789_123456789_123456789_123456789_123456789_1234 (
882
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
883
 key a052_long_123456789_123456789_123456789_123456789_123456789_1234 (
884
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
885
 key a053_long_123456789_123456789_123456789_123456789_123456789_1234 (
886
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
887
 key a054_long_123456789_123456789_123456789_123456789_123456789_1234 (
888
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
889
 key a055_long_123456789_123456789_123456789_123456789_123456789_1234 (
890
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
891
 key a056_long_123456789_123456789_123456789_123456789_123456789_1234 (
892
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
893
 key a057_long_123456789_123456789_123456789_123456789_123456789_1234 (
894
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
895
 key a058_long_123456789_123456789_123456789_123456789_123456789_1234 (
896
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
897
 key a059_long_123456789_123456789_123456789_123456789_123456789_1234 (
898
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
899
900
 key a060_long_123456789_123456789_123456789_123456789_123456789_1234 (
901
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
902
 key a061_long_123456789_123456789_123456789_123456789_123456789_1234 (
903
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
904
 key a062_long_123456789_123456789_123456789_123456789_123456789_1234 (
905
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
906
 key a063_long_123456789_123456789_123456789_123456789_123456789_1234 (
907
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
908
 key a064_long_123456789_123456789_123456789_123456789_123456789_1234 (
909
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16)
910
);
911
912
# Check that the table is not corrupted
913
show create table t1;
914
flush tables;
915
show create table t1;
916
917
# Repeat test using ALTER to add indexes
918
919
drop table t1;
920
create table t1 (c1 int, c2 int, c3 int, c4 int, c5 int, c6 int, c7 int, 
921
c8 int, c9 int, c10 int, c11 int, c12 int, c13 int, c14 int, c15 int, c16 int);
922
923
alter table t1
924
925
 add key a001_long_123456789_123456789_123456789_123456789_123456789_1234 (
926
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
927
 add key a002_long_123456789_123456789_123456789_123456789_123456789_1234 (
928
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
929
 add key a003_long_123456789_123456789_123456789_123456789_123456789_1234 (
930
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
931
 add key a004_long_123456789_123456789_123456789_123456789_123456789_1234 (
932
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
933
 add key a005_long_123456789_123456789_123456789_123456789_123456789_1234 (
934
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
935
 add key a006_long_123456789_123456789_123456789_123456789_123456789_1234 (
936
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
937
 add key a007_long_123456789_123456789_123456789_123456789_123456789_1234 (
938
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
939
 add key a008_long_123456789_123456789_123456789_123456789_123456789_1234 (
940
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
941
 add key a009_long_123456789_123456789_123456789_123456789_123456789_1234 (
942
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
943
944
 add key a010_long_123456789_123456789_123456789_123456789_123456789_1234 (
945
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
946
 add key a011_long_123456789_123456789_123456789_123456789_123456789_1234 (
947
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
948
 add key a012_long_123456789_123456789_123456789_123456789_123456789_1234 (
949
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
950
 add key a013_long_123456789_123456789_123456789_123456789_123456789_1234 (
951
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
952
 add key a014_long_123456789_123456789_123456789_123456789_123456789_1234 (
953
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
954
 add key a015_long_123456789_123456789_123456789_123456789_123456789_1234 (
955
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
956
 add key a016_long_123456789_123456789_123456789_123456789_123456789_1234 (
957
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
958
 add key a017_long_123456789_123456789_123456789_123456789_123456789_1234 (
959
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
960
 add key a018_long_123456789_123456789_123456789_123456789_123456789_1234 (
961
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
962
 add key a019_long_123456789_123456789_123456789_123456789_123456789_1234 (
963
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
964
965
 add key a020_long_123456789_123456789_123456789_123456789_123456789_1234 (
966
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
967
 add key a021_long_123456789_123456789_123456789_123456789_123456789_1234 (
968
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
969
 add key a022_long_123456789_123456789_123456789_123456789_123456789_1234 (
970
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
971
 add key a023_long_123456789_123456789_123456789_123456789_123456789_1234 (
972
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
973
 add key a024_long_123456789_123456789_123456789_123456789_123456789_1234 (
974
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
975
 add key a025_long_123456789_123456789_123456789_123456789_123456789_1234 (
976
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
977
 add key a026_long_123456789_123456789_123456789_123456789_123456789_1234 (
978
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
979
 add key a027_long_123456789_123456789_123456789_123456789_123456789_1234 (
980
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
981
 add key a028_long_123456789_123456789_123456789_123456789_123456789_1234 (
982
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
983
 add key a029_long_123456789_123456789_123456789_123456789_123456789_1234 (
984
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
985
986
 add key a030_long_123456789_123456789_123456789_123456789_123456789_1234 (
987
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
988
 add key a031_long_123456789_123456789_123456789_123456789_123456789_1234 (
989
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
990
 add key a032_long_123456789_123456789_123456789_123456789_123456789_1234 (
991
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
992
 add key a033_long_123456789_123456789_123456789_123456789_123456789_1234 (
993
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
994
 add key a034_long_123456789_123456789_123456789_123456789_123456789_1234 (
995
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
996
 add key a035_long_123456789_123456789_123456789_123456789_123456789_1234 (
997
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
998
 add key a036_long_123456789_123456789_123456789_123456789_123456789_1234 (
999
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1000
 add key a037_long_123456789_123456789_123456789_123456789_123456789_1234 (
1001
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1002
 add key a038_long_123456789_123456789_123456789_123456789_123456789_1234 (
1003
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1004
 add key a039_long_123456789_123456789_123456789_123456789_123456789_1234 (
1005
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1006
1007
 add key a040_long_123456789_123456789_123456789_123456789_123456789_1234 (
1008
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1009
 add key a041_long_123456789_123456789_123456789_123456789_123456789_1234 (
1010
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1011
 add key a042_long_123456789_123456789_123456789_123456789_123456789_1234 (
1012
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1013
 add key a043_long_123456789_123456789_123456789_123456789_123456789_1234 (
1014
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1015
 add key a044_long_123456789_123456789_123456789_123456789_123456789_1234 (
1016
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1017
 add key a045_long_123456789_123456789_123456789_123456789_123456789_1234 (
1018
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1019
 add key a046_long_123456789_123456789_123456789_123456789_123456789_1234 (
1020
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1021
 add key a047_long_123456789_123456789_123456789_123456789_123456789_1234 (
1022
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1023
 add key a048_long_123456789_123456789_123456789_123456789_123456789_1234 (
1024
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1025
 add key a049_long_123456789_123456789_123456789_123456789_123456789_1234 (
1026
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1027
1028
 add key a050_long_123456789_123456789_123456789_123456789_123456789_1234 (
1029
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1030
 add key a051_long_123456789_123456789_123456789_123456789_123456789_1234 (
1031
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1032
 add key a052_long_123456789_123456789_123456789_123456789_123456789_1234 (
1033
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1034
 add key a053_long_123456789_123456789_123456789_123456789_123456789_1234 (
1035
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1036
 add key a054_long_123456789_123456789_123456789_123456789_123456789_1234 (
1037
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1038
 add key a055_long_123456789_123456789_123456789_123456789_123456789_1234 (
1039
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1040
 add key a056_long_123456789_123456789_123456789_123456789_123456789_1234 (
1041
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1042
 add key a057_long_123456789_123456789_123456789_123456789_123456789_1234 (
1043
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1044
 add key a058_long_123456789_123456789_123456789_123456789_123456789_1234 (
1045
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1046
 add key a059_long_123456789_123456789_123456789_123456789_123456789_1234 (
1047
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1048
1049
 add key a060_long_123456789_123456789_123456789_123456789_123456789_1234 (
1050
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1051
 add key a061_long_123456789_123456789_123456789_123456789_123456789_1234 (
1052
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1053
 add key a062_long_123456789_123456789_123456789_123456789_123456789_1234 (
1054
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1055
 add key a063_long_123456789_123456789_123456789_123456789_123456789_1234 (
1056
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16),
1057
 add key a064_long_123456789_123456789_123456789_123456789_123456789_1234 (
1058
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16);
1059
1060
show create table t1;
1061
flush tables;
1062
show create table t1;
1063
1064
# Test the server limits; if any of these pass, all above tests need
1065
# to be rewritten to hit the limit
1066
#
1067
# Ensure limit is really 64 keys
1068
--error 1069
1069
alter table t1 add key 
1070
 a065_long_123456789_123456789_123456789_123456789_123456789_1234 (
1071
  c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16);
1072
1073
drop table t1;
1074
1075
# Ensure limit is really 16 key parts per key
1076
1077
create table t1 (c1 int, c2 int, c3 int, c4 int, c5 int, c6 int, c7 int, 
1078
c8 int, c9 int, c10 int, c11 int, c12 int, c13 int, c14 int, c15 int, 
1079
c16 int, c17 int);
1080
1081
# Get error for max key parts
1082
--error 1070
1083
alter table t1 add key i1 (
1084
 c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16, c17);
1085
1086
# Get error for max key-name length
1087
--error 1059
1088
alter table t1 add key 
1089
 a001_long_123456789_123456789_123456789_123456789_123456789_12345 (c1);
1090
1091
show create table t1;
1092
1093
drop table t1;
1094
1095
--echo
1096
--echo Bug #26104 Bug on foreign key class constructor
1097
--echo
1098
--echo Check that ref_columns is initalized correctly in the constructor
1099
--echo and semantic checks in mysql_prepare_table work.
1100
--echo
1101
--echo We do not need a storage engine that supports foreign keys
1102
--echo for this test, as the checks are purely syntax-based, and the
1103
--echo syntax is supported for all engines.
1104
--echo
1105
--disable_warnings
1106
drop table if exists t1,t2;
1107
--enable_warnings
1108
1109
create table t1(a int not null, b int not null, primary key (a, b));
1110
--error ER_WRONG_FK_DEF
1111
create table t2(a int not null, b int not null, c int not null, primary key (a),
1112
foreign key fk_bug26104 (b,c) references t1(a));
1113
drop table t1;
1114
1115
#
1116
# Bug#15130:CREATE .. SELECT was denied to use advantages of the SQL_BIG_RESULT.
1117
#
1118
create table t1(f1 int,f2 int);
1119
insert into t1 value(1,1),(1,2),(1,3),(2,1),(2,2),(2,3);
1120
flush status;
1121
create table t2 select sql_big_result f1,count(f2) from t1 group by f1;
1122
show status like 'handler_read%';
1123
drop table t1,t2;
1124
1125
#
1126
# Bug #25162: Backing up DB from 5.1 adds 'USING BTREE' to KEYs on table creates
1127
#
1128
1129
# Show that the old syntax for index type is supported
1130
CREATE TABLE t1(c1 VARCHAR(33), KEY USING BTREE (c1));
1131
DROP TABLE t1;
1132
1133
# Show that the new syntax for index type is supported
1134
CREATE TABLE t1(c1 VARCHAR(33), KEY (c1) USING BTREE);
1135
DROP TABLE t1;
1136
1137
# Show that in case of multiple index type definitions, the last one takes 
1138
# precedence
1139
1140
CREATE TABLE t1(c1 VARCHAR(33), KEY USING BTREE (c1) USING HASH) ENGINE=MEMORY;
1141
SHOW INDEX FROM t1;
1142
DROP TABLE t1;
1143
1144
CREATE TABLE t1(c1 VARCHAR(33), KEY USING HASH (c1) USING BTREE) ENGINE=MEMORY;
1145
SHOW INDEX FROM t1;
1146
DROP TABLE t1;
1147
1148
1149
--echo End of 5.0 tests
1150
1151
#
1152
# Test of behaviour with CREATE ... SELECT
1153
#
1154
1155
CREATE TABLE t1 (a int, b int);
1156
insert into t1 values (1,1),(1,2);
1157
--error ER_DUP_ENTRY
1158
CREATE TABLE t2 (primary key (a)) select * from t1;
1159
# This should give warning
1160
drop table if exists t2;
1161
--error ER_DUP_ENTRY
1162
CREATE TEMPORARY TABLE t2 (primary key (a)) select * from t1;
1163
# This should give warning
1164
drop table if exists t2;
722.2.15 by Monty Taylor
Fixed create.test.
1165
# TODO: Bug lp:311072
1166
#CREATE TABLE t2 (a int, b int, primary key (a));
1167
#--error ER_DUP_ENTRY
1168
#CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
1169
#SELECT * from t2;
1170
#TRUNCATE table t2;
1171
#--error ER_DUP_ENTRY
1172
#INSERT INTO t2 select * from t1;
1173
#SELECT * from t2;
1174
#drop table t2;
1 by brian
clean slate
1175
1176
CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a));
1177
--error ER_DUP_ENTRY
1178
CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
1179
SELECT * from t2;
1180
TRUNCATE table t2;
1181
--error ER_DUP_ENTRY
1182
INSERT INTO t2 select * from t1;
1183
SELECT * from t2;
1184
drop table t1,t2;
1185
1186
1187
#
1188
# Test incorrect database names
1189
#
1190
1191
--error 1102
1192
CREATE DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
1193
--error 1102
1194
DROP DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
1195
1196
# TODO: enable these tests when RENAME DATABASE is implemented.
1197
# --error 1049
1198
# RENAME DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa TO a;
1199
# --error 1102
1200
# RENAME DATABASE mysqltest TO aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
1201
# create database mysqltest;
1202
# --error 1102
1203
# RENAME DATABASE mysqltest TO aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
1204
# drop database mysqltest;
1205
1206
--error 1102
1207
USE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
1208
--error 1102
1209
SHOW CREATE DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
1210
1211
#
1212
# Bug#21432 Database/Table name limited to 64 bytes, not chars, problems with multi-byte
1213
#
1214
1215
create database имя_базы_в_кодировке_утф8_длиной_больше_чем_45;
1216
use имя_базы_в_кодировке_утф8_длиной_больше_чем_45;
1217
select database();
1218
use test;
1219
1220
select SCHEMA_NAME from information_schema.schemata
1221
where schema_name='имя_базы_в_кодировке_утф8_длиной_больше_чем_45';
1222
1223
drop database имя_базы_в_кодировке_утф8_длиной_больше_чем_45;
1224
create table имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48
1225
(
1226
  имя_поля_в_кодировке_утф8_длиной_больше_чем_45 int,
1227
  index имя_индекса_в_кодировке_утф8_длиной_больше_чем_48 (имя_поля_в_кодировке_утф8_длиной_больше_чем_45)
1228
);
1229
1230
722.2.15 by Monty Taylor
Fixed create.test.
1231
# database, table, field, key
1 by brian
clean slate
1232
select * from имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
1233
1234
select TABLE_NAME from information_schema.tables where
1235
table_schema='test';
1236
1237
select COLUMN_NAME from information_schema.columns where
1238
table_schema='test';
1239
1240
select INDEX_NAME from information_schema.statistics where
1241
table_schema='test';
1242
1243
show create table имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
722.2.15 by Monty Taylor
Fixed create.test.
1244
1 by brian
clean slate
1245
drop table имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
722.2.15 by Monty Taylor
Fixed create.test.
1246
1 by brian
clean slate
1247
1248
#
1249
# Bug#25629 CREATE TABLE LIKE does not work with INFORMATION_SCHEMA
1250
#
1251
create table t1 like information_schema.processlist;
1252
show create table t1;
1253
drop table t1;
1254
create temporary table t1 like information_schema.processlist;
1255
show create table t1;
1256
drop table t1;
1257
1258
###########################################################################
1259
1260
--echo
1261
--echo # --
1262
--echo # -- Bug#21380: DEFAULT definition not always transfered by CREATE
1263
--echo # -- TABLE/SELECT to the new table.
1264
--echo # --
1265
--echo
1266
1267
1268
--disable_warnings
1269
DROP TABLE IF EXISTS t1;
1270
DROP TABLE IF EXISTS t2;
1271
--enable_warnings
1272
1273
--echo
1274
1275
CREATE TABLE t1(
1276
  c1 INT DEFAULT 12 COMMENT 'column1',
1277
  c2 INT NULL COMMENT 'column2',
1278
  c3 INT NOT NULL COMMENT 'column3',
722.2.15 by Monty Taylor
Fixed create.test.
1279
  c4 VARCHAR(255) NOT NULL DEFAULT 'a',
1 by brian
clean slate
1280
  c5 VARCHAR(255) COLLATE utf8_unicode_ci NULL DEFAULT 'b',
1281
  c6 VARCHAR(255))
722.2.15 by Monty Taylor
Fixed create.test.
1282
  COLLATE utf8_bin;
1 by brian
clean slate
1283
1284
--echo
1285
1286
SHOW CREATE TABLE t1;
1287
1288
--echo
1289
1290
CREATE TABLE t2 AS SELECT * FROM t1;
1291
1292
--echo
1293
1294
SHOW CREATE TABLE t2;
1295
1296
--echo
1297
1298
DROP TABLE t2;
1299
1300
--echo
1301
--echo # -- End of test case for Bug#21380.
1302
1303
###########################################################################
1304
1305
--echo
1306
--echo # --
1307
--echo # -- Bug#18834: ALTER TABLE ADD INDEX on table with two timestamp fields
1308
--echo # --
1309
--echo
1310
1311
--disable_warnings
1312
DROP TABLE IF EXISTS t1;
1313
DROP TABLE IF EXISTS t2;
1314
DROP TABLE IF EXISTS t3;
1315
--enable_warnings
1316
1317
--echo
1318
1319
CREATE TABLE t1(c1 TIMESTAMP, c2 TIMESTAMP);
1320
1321
--echo
1322
1323
--echo
1324
CREATE TABLE t2(c1 TIMESTAMP, c2 TIMESTAMP DEFAULT 0);
722.2.15 by Monty Taylor
Fixed create.test.
1325
drop table t2;
1 by brian
clean slate
1326
1327
--echo
1328
CREATE TABLE t2(c1 TIMESTAMP, c2 TIMESTAMP);
722.2.15 by Monty Taylor
Fixed create.test.
1329
drop table t2;
1 by brian
clean slate
1330
1331
--echo
1332
--echo # -- Check that NULL column still can be created.
1333
CREATE TABLE t2(c1 TIMESTAMP NULL);
1334
1335
--echo
1336
--echo # -- Check ALTER TABLE.
1337
ALTER TABLE t1 ADD INDEX(c1);
1338
1339
--echo
1340
--echo # -- Check DATETIME.
1341
--echo
1342
1343
CREATE TABLE t3(c1 DATETIME NOT NULL);
1344
INSERT INTO t3 VALUES (0);
1345
1346
--echo
1347
ALTER TABLE t3 ADD INDEX(c1);
1348
1349
--echo
1350
--echo # -- Cleanup.
1351
1352
DROP TABLE t1;
1353
DROP TABLE t2;
1354
DROP TABLE t3;
1355
1356
--echo
1357
--echo # -- End of Bug#18834.
1358