29
create table t2 engine=heap select * from t1;
30
create temporary table t2 engine=MEMORY select * from t1;
31
32
create table t2 select auto+1 from t1;
32
33
drop table if exists t1,t2;
34
35
create table t1 (b char(0) not null, index(b));
36
create table t1 (a int not null,b text) engine=heap;
37
create temporary table t1 (a int not null,b text) engine=MEMORY;
37
38
drop table if exists t1;
40
create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid)) engine=heap;
41
create temporary table t1 (ordid int not null auto_increment, ord varchar(50) not null, primary key (ord,ordid)) engine=MEMORY;
43
44
create table not_existing_database.test (a int);
44
45
create table `a/a` (a int);
46
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
45
47
show create table `a/a`;
46
48
create table t1 like `a/a`;
167
170
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));
171
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
168
172
show create table t1;
170
174
create table t1 select if(1,'1','0'), month("2002-08-02");
334
348
# Test types of data for create select with functions
337
create table t1(a int,b int,c int unsigned,d date,e char,f datetime,g time,h blob);
351
create table t1(a int,b int,c int,d date,e char,f datetime,h blob);
338
352
insert into t1(a)values(1);
339
insert into t1(a,b,c,d,e,f,g,h)
340
values(2,-2,2,'1825-12-14','a','2003-1-1 3:2:1','4:3:2','binary data');
353
insert into t1(a,b,c,d,e,f,h)
354
values(2,-2,2,'1825-12-14','a','2003-01-01 03:02:01','binary data');
341
355
select * from t1;
343
ifnull(b,cast(-7 as signed)) as b,
344
ifnull(c,cast(7 as unsigned)) as c,
345
359
ifnull(d,cast('2000-01-01' as date)) as d,
346
360
ifnull(e,cast('b' as char)) as e,
347
361
ifnull(f,cast('2000-01-01' as datetime)) as f,
348
ifnull(g,cast('5:4:3' as time)) as g,
349
ifnull(h,cast('yet another binary data' as binary)) as h,
350
addtime(cast('1:0:0' as time),cast('1:0:0' as time)) as dd
362
ifnull(h,cast('yet another binary data' as binary)) as h
356
ifnull(b,cast(-7 as signed)) as b,
357
ifnull(c,cast(7 as unsigned)) as c,
358
370
ifnull(d,cast('2000-01-01' as date)) as d,
359
371
ifnull(e,cast('b' as char)) as e,
360
372
ifnull(f,cast('2000-01-01' as datetime)) as f,
361
ifnull(g,cast('5:4:3' as time)) as g,
362
ifnull(h,cast('yet another binary data' as binary)) as h,
363
addtime(cast('1:0:0' as time),cast('1:0:0' as time)) as dd
373
ifnull(h,cast('yet another binary data' as binary)) as h
366
376
select * from t2;
367
377
drop table t1, t2;
369
create table t1 (a tinyint, b smallint, c mediumint, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), i year, j date, k timestamp, l datetime, m enum('a','b'), n set('a','b'), o char(10));
370
create table t2 select ifnull(a,a), ifnull(b,b), ifnull(c,c), ifnull(d,d), ifnull(e,e), ifnull(f,f), ifnull(g,g), ifnull(h,h), ifnull(i,i), ifnull(j,j), ifnull(k,k), ifnull(l,l), ifnull(m,m), ifnull(n,n), ifnull(o,o) from t1;
379
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));
380
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;
381
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
371
382
show create table t2;
372
383
drop table t1,t2;
409
422
select database();
410
423
drop database mysqltest;
411
424
select database();
413
# Connect without a database as user mysqltest_1
414
create user mysqltest_1;
415
connect (user1,localhost,mysqltest_1,,*NO-ONE*);
417
select database(), user();
420
drop user mysqltest_1;
424
428
# Test for Bug 856 'Naming a key "Primary" causes trouble'
428
create table t1 (a int, index `primary` (a));
430
create table t1 (a int, index `PRIMARY` (a));
432
create table t1 (`primary` int, index(`primary`));
433
show create table t1;
434
create table t2 (`PRIMARY` int, index(`PRIMARY`));
435
show create table t2;
437
create table t3 (a int);
439
alter table t3 add index `primary` (a);
441
alter table t3 add index `PRIMARY` (a);
443
create table t4 (`primary` int);
444
alter table t4 add index(`primary`);
445
show create table t4;
446
create table t5 (`PRIMARY` int);
447
alter table t5 add index(`PRIMARY`);
448
show create table t5;
450
drop table t1, t2, t3, t4, t5;
431
## TODO: Is this really a bug? It works in Drizzle. Should it?
433
#create table t1 (a int, index `primary` (a));
435
#create table t1 (a int, index `PRIMARY` (a));
437
#create table t1 (`primary` int, index(`primary`));
438
#--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
439
#show create table t1;
440
#create table t2 (`PRIMARY` int, index(`PRIMARY`));
441
#--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
442
#show create table t2;
444
#create table t3 (a int);
446
#alter table t3 add index `primary` (a);
448
#alter table t3 add index `PRIMARY` (a);
450
#create table t4 (`primary` int);
451
#alter table t4 add index(`primary`);
452
#--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
453
#show create table t4;
454
#create table t5 (`PRIMARY` int);
455
#alter table t5 add index(`PRIMARY`);
456
#--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
457
#show create table t5;
459
#drop table t1, t2, t3, t4, t5;
453
462
# bug #3266 TEXT in CREATE TABLE SELECT
565
555
# calculation of number of NULLs.
567
557
CREATE TABLE t2 (
568
a int(11) default NULL
570
560
insert into t2 values(111);
573
563
create table t1 (
574
a varchar(12) charset utf8 collate utf8_bin not null,
564
a varchar(12) collate utf8_bin not null,
575
565
b int not null, primary key (a)
576
566
) select a, 1 as b from t2 ;
567
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
577
568
show create table t1;
581
572
create table t1 (
582
a varchar(12) charset utf8 collate utf8_bin not null,
573
a varchar(12) collate utf8_bin not null,
583
574
b int not null, primary key (a)
584
575
) select a, 1 as c from t2 ;
585
show create table t1;
589
577
create table t1 (
590
a varchar(12) charset utf8 collate utf8_bin not null,
578
a varchar(12) collate utf8_bin not null,
591
579
b int null, primary key (a)
592
580
) select a, 1 as c from t2 ;
593
show create table t1;
598
a varchar(12) charset utf8 collate utf8_bin not null,
599
b int not null, primary key (a)
600
) select 'a' as a , 1 as b from t2 ;
601
show create table t1;
606
a varchar(12) charset utf8 collate utf8_bin,
607
b int not null, primary key (a)
608
) select 'a' as a , 1 as b from t2 ;
581
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
582
show create table t1;
586
a varchar(12) collate utf8_bin not null,
587
b int not null, primary key (a)
588
) select 'a' as a , 1 as b from t2 ;
589
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
590
show create table t1;
594
a varchar(12) collate utf8_bin,
595
b int not null, primary key (a)
596
) select 'a' as a , 1 as b from t2 ;
597
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
609
598
show create table t1;
610
599
drop table t1, t2;
688
657
create table t1 select * from t1;
689
658
# Error which happens before select_create::prepare()
690
659
--error ER_CANT_AGGREGATE_2COLLATIONS
691
create table t1 select coalesce('a' collate latin1_swedish_ci,'b' collate latin1_bin);
660
create table t1 select coalesce('a' collate utf8_swedish_ci,'b' collate utf8_bin);
692
661
# Error during table creation
693
662
--error ER_KEY_COLUMN_DOES_NOT_EXITS
694
663
create table t1 (primary key(a)) select "b" as b;
695
664
# Error in select_create::prepare() which is not related to table creation
696
create table t1 (a int);
697
--error ER_WRONG_VALUE_COUNT_ON_ROW
698
create table if not exists t1 select 1 as a, 2 as b;
665
# TODO: This really should be failing...
666
# create table t1 (a int);
667
# --error ER_WRONG_VALUE_COUNT_ON_ROW
668
# create table if not exists t1 select 1 as a, 2 as b;
700
670
# Finally error which happens during insert
701
671
--error ER_DUP_ENTRY
702
672
create table t1 (primary key (a)) (select 1 as a) union all (select 1 as a);
703
673
# What happens if table already exists ?
704
674
create table t1 (i int);
705
--error ER_TABLE_EXISTS_ERROR
706
create table t1 select 1 as i;
675
# TODO: BUG lp:311045
676
#--error ER_TABLE_EXISTS_ERROR
677
#create table t1 select 1 as i;
707
678
create table if not exists t1 select 1 as i;
708
679
select * from t1;
709
681
# Error before select_create::prepare()
710
682
--error ER_CANT_AGGREGATE_2COLLATIONS
711
create table t1 select coalesce('a' collate latin1_swedish_ci,'b' collate latin1_bin);
683
create table t1 select coalesce('a' collate utf8_swedish_ci,'b' collate utf8_bin);
713
684
# Error which happens during insertion of rows
714
alter table t1 add primary key (i);
716
create table if not exists t1 (select 2 as i) union all (select 2 as i);
685
# TODO: Bug lp:311072
686
# create table t1 (i int);
687
# alter table t1 add primary key (i);
688
# --error ER_DUP_ENTRY
689
# create table if not exists t1 (select 2 as i) union all (select 2 as i);
721
694
# Base vs temporary tables dillema (a.k.a. bug#24508 "Inconsistent
738
# CREATE TABLE ... SELECT and LOCK TABLES
740
# There is little sense in using CREATE TABLE ... SELECT under
741
# LOCK TABLES as it mostly does not work. At least we check that
742
# the server doesn't crash, hang and produces sensible errors.
743
# Includes test for bug #20662 "Infinite loop in CREATE TABLE
744
# IF NOT EXISTS ... SELECT with locked tables".
745
create table t1 (i int);
746
insert into t1 values (1), (2);
748
--error ER_TABLE_NOT_LOCKED
749
create table t2 select * from t1;
750
--error ER_TABLE_NOT_LOCKED
751
create table if not exists t2 select * from t1;
753
create table t2 (j int);
755
--error ER_TABLE_NOT_LOCKED
756
create table t2 select * from t1;
757
# This should not be ever allowed as it will undermine
758
# lock-all-at-once approach
759
--error ER_TABLE_NOT_LOCKED
760
create table if not exists t2 select * from t1;
762
lock table t1 read, t2 read;
763
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
764
create table t2 select * from t1;
765
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
766
create table if not exists t2 select * from t1;
768
lock table t1 read, t2 write;
769
--error ER_TABLE_EXISTS_ERROR
770
create table t2 select * from t1;
771
# This is the only case which really works.
772
create table if not exists t2 select * from t1;
777
# OTOH CREATE TEMPORARY TABLE ... SELECT should work
778
# well under LOCK TABLES.
780
create temporary table t2 select * from t1;
781
create temporary table if not exists t2 select * from t1;
788
711
# Bug#21772: can not name a column 'upgrade' when create a table
790
713
create table t1 (upgrade int);
1273
1198
select INDEX_NAME from information_schema.statistics where
1274
1199
table_schema='test';
1276
select TABLE_NAME from information_schema.views where
1277
table_schema='test';
1201
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1279
1202
show create table имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
1280
show create view имя_вью_кодировке_утф8_длиной_больше_чем_42;
1282
# procedure, function, trigger
1284
create trigger имя_триггера_в_кодировке_утф8_длиной_больше_чем_49
1285
before insert on имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48 for each row set @a:=1;
1286
select TRIGGER_NAME from information_schema.triggers where
1287
trigger_schema='test';
1288
drop trigger имя_триггера_в_кодировке_утф8_длиной_больше_чем_49;
1291
очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66
1292
before insert on имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48 for each row set @a:=1;
1294
drop trigger очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66;
1296
create procedure имя_процедуры_в_кодировке_утф8_длиной_больше_чем_50()
1299
select ROUTINE_NAME from information_schema.routines where
1300
routine_schema='test';
1301
drop procedure имя_процедуры_в_кодировке_утф8_длиной_больше_чем_50;
1303
create procedure очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66()
1307
create function имя_функции_в_кодировке_утф8_длиной_больше_чем_49()
1310
select ROUTINE_NAME from information_schema.routines where
1311
routine_schema='test';
1312
drop function имя_функции_в_кодировке_утф8_длиной_больше_чем_49;
1314
create function очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66()
1318
drop view имя_вью_кодировке_утф8_длиной_больше_чем_42;
1319
1204
drop table имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
1323
# Bug#21136 CREATE TABLE SELECT within CREATE TABLE SELECT causes server crash
1327
drop table if exists t1,t2,t3;
1328
drop function if exists f1;
1332
create function f1() returns int
1335
create temporary table t3 select 1 i;
1336
set res:= (select count(*) from t1);
1337
drop temporary table t3;
1341
create table t1 as select 1;
1342
create table t2 as select f1() from t1;
1347
1208
# Bug#25629 CREATE TABLE LIKE does not work with INFORMATION_SCHEMA
1349
1211
create table t1 like information_schema.processlist;
1212
create table t1 like information_schema.processlist engine=innodb;
1350
1213
show create table t1;
1352
1216
create temporary table t1 like information_schema.processlist;
1353
show create table t1;
1355
create table t1 like information_schema.character_sets;
1217
create temporary table t1 like information_schema.processlist engine=myisam;
1356
1218
show create table t1;