412
412
# ORDER BY on not primary key
415
eval create $temp table t1 (
415
eval CREATE TABLE t1 (
416
416
user_name varchar(12),
418
418
subscribed char(1),
419
user_id int DEFAULT '0' NOT NULL,
419
user_id int(11) DEFAULT '0' NOT NULL,
422
422
access_date date,
423
424
approved datetime,
424
dummy_primary_key int NOT NULL auto_increment,
425
dummy_primary_key int(11) NOT NULL auto_increment,
425
426
PRIMARY KEY (dummy_primary_key)
426
427
) ENGINE=$engine_type;
427
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','2000-09-07 23:06:59',1);
428
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','2000-09-07 23:06:59',2);
429
INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','2000-09-07 23:06:59',3);
430
INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','2000-09-07 23:06:59',4);
431
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','2000-09-07 23:06:59',5);
432
select user_name, password , subscribed, user_id, quota, weight, access_date, approved, dummy_primary_key from t1 order by user_name;
428
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','23:06:59','2000-09-07 23:06:59',1);
429
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','23:06:59','2000-09-07 23:06:59',2);
430
INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','23:06:59','2000-09-07 23:06:59',3);
431
INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','23:06:59','2000-09-07 23:06:59',4);
432
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','23:06:59','2000-09-07 23:06:59',5);
433
select user_name, password , subscribed, user_id, quota, weight, access_date, access_time, approved, dummy_primary_key from t1 order by user_name;
436
437
# Testing of tables without primary keys
439
eval create $temp table t1 (
440
id int NOT NULL auto_increment,
441
parent_id int DEFAULT '0' NOT NULL,
442
level int DEFAULT '0' NOT NULL,
440
eval CREATE TABLE t1 (
441
id int(11) NOT NULL auto_increment,
442
parent_id int(11) DEFAULT '0' NOT NULL,
443
level tinyint(4) DEFAULT '0' NOT NULL,
444
445
KEY parent_id (parent_id),
445
446
KEY level (level)
499
500
# Test of opening table twice and timestamps
505
eval create $temp table t1 (a int not null, b timestamp not null, primary key (a)) engine=$engine_type;
503
eval CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=$engine_type;
506
504
insert into t1 (a) values(1),(2),(3);
507
505
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
508
506
select a from t1 natural join t1 as t2 where b >= @a order by a;
509
507
update t1 set a=5 where a=1;
510
508
select a from t1;
514
512
# Test with variable length primary key
516
eval create $temp table t1 (a varchar(100) not null, primary key(a), b int not null) engine=$engine_type;
514
eval create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=$engine_type;
517
515
insert into t1 values("hello",1),("world",2);
518
516
select * from t1 order by b desc;
519
eval alter table t1 ENGINE=$engine_type;
520
518
--replace_column 7 #
521
519
show keys from t1;
561
559
# Crash when using many tables (Test case by Jeremy D Zawodny)
564
eval create $temp table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h int, i int, j int, k int, l int, m int, n int, o int, p int, q int, r int, s int, t int, u int, v int, w int, x int, y int, z int, a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, b1 int, b2 int, b3 int, b4 int, b5 int, b6 int) engine = $engine_type;
562
eval create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h int, i int, j int, k int, l int, m int, n int, o int, p int, q int, r int, s int, t int, u int, v int, w int, x int, y int, z int, a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, b1 int, b2 int, b3 int, b4 int, b5 int, b6 int) engine = $engine_type;
565
563
insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
566
564
--replace_column 9 #
567
565
explain select * from t1 where a > 0 and a < 50;
572
eval create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=$engine_type;
573
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
574
LOCK TABLES t1 WRITE;
576
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
582
eval create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=$engine_type;
583
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
584
LOCK TABLES t1 WRITE;
587
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
589
insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
591
select id,id3 from t1;
571
596
# Test prefix key
573
eval create $temp table t1 (a char(20), unique (a(5))) engine=$engine_type;
598
eval create table t1 (a char(20), unique (a(5))) engine=$engine_type;
575
eval create $temp table t1 (a char(20), index (a(5))) engine=$engine_type;
600
eval create table t1 (a char(20), index (a(5))) engine=$engine_type;
576
601
show create table t1;
689
eval create $temp table t1 (t int not null default 1, key (t)) engine=$engine_type;
717
eval create table t1 (t int not null default 1, key (t)) engine=$engine_type;
722
# Test of multi-table-delete
725
eval CREATE TABLE t1 (
726
number bigint(20) NOT NULL default '0',
727
cname char(15) NOT NULL default '',
728
carrier_id smallint(6) NOT NULL default '0',
729
privacy tinyint(4) NOT NULL default '0',
730
last_mod_date timestamp NOT NULL,
731
last_mod_id smallint(6) NOT NULL default '0',
732
last_app_date timestamp NOT NULL,
733
last_app_id smallint(6) default '-1',
734
version smallint(6) NOT NULL default '0',
735
assigned_scps int(11) default '0',
736
status tinyint(4) default '0'
737
) ENGINE=$engine_type;
738
INSERT INTO t1 VALUES (4077711111,'SeanWheeler',90,2,20020111112846,500,00000000000000,-1,2,3,1);
739
INSERT INTO t1 VALUES (9197722223,'berry',90,3,20020111112809,500,20020102114532,501,4,10,0);
740
INSERT INTO t1 VALUES (650,'San Francisco',0,0,20011227111336,342,00000000000000,-1,1,24,1);
741
INSERT INTO t1 VALUES (302467,'Sue\'s Subshop',90,3,20020109113241,500,20020102115111,501,7,24,0);
742
INSERT INTO t1 VALUES (6014911113,'SudzCarwash',520,1,20020102115234,500,20020102115259,501,33,32768,0);
743
INSERT INTO t1 VALUES (333,'tubs',99,2,20020109113440,501,20020109113440,500,3,10,0);
744
eval CREATE TABLE t2 (
745
number bigint(20) NOT NULL default '0',
746
cname char(15) NOT NULL default '',
747
carrier_id smallint(6) NOT NULL default '0',
748
privacy tinyint(4) NOT NULL default '0',
749
last_mod_date timestamp NOT NULL,
750
last_mod_id smallint(6) NOT NULL default '0',
751
last_app_date timestamp NOT NULL,
752
last_app_id smallint(6) default '-1',
753
version smallint(6) NOT NULL default '0',
754
assigned_scps int(11) default '0',
755
status tinyint(4) default '0'
756
) ENGINE=$engine_type;
757
INSERT INTO t2 VALUES (4077711111,'SeanWheeler',0,2,20020111112853,500,00000000000000,-1,2,3,1);
758
INSERT INTO t2 VALUES (9197722223,'berry',90,3,20020111112818,500,20020102114532,501,4,10,0);
759
INSERT INTO t2 VALUES (650,'San Francisco',90,0,20020109113158,342,00000000000000,-1,1,24,1);
760
INSERT INTO t2 VALUES (333,'tubs',99,2,20020109113453,501,20020109113453,500,3,10,0);
763
delete t1, t2 from t1 left join t2 on t1.number=t2.number where (t1.carrier_id=90 and t1.number=t2.number) or (t2.carrier_id=90 and t1.number=t2.number) or (t1.carrier_id=90 and t2.number is null);
694
770
# A simple test with some isolation levels
695
771
# TODO: Make this into a test using replication to really test how
699
eval create $temp table t1 (id int not null auto_increment, code int not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=$engine_type;
775
eval create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=$engine_type;
702
778
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
741
841
# Test of multi-table-delete with foreign key constraints
744
eval create $temp table t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=$engine_type;
745
eval create $temp table t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE ) ENGINE=$engine_type;
844
eval CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=$engine_type;
845
eval CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE ) ENGINE=$engine_type;
746
846
insert into t1 set id=1;
747
847
insert into t2 set id=1, t1_id=1;
748
848
delete t1,t2 from t1,t2 where t1.id=t2.t1_id;
749
849
select * from t1;
750
850
select * from t2;
751
851
drop table t2,t1;
752
eval create $temp table t1(id INT NOT NULL, PRIMARY KEY (id)) ENGINE=$engine_type;
753
eval create $temp table t2(id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id) ) ENGINE=$engine_type;
852
eval CREATE TABLE t1(id INT NOT NULL, PRIMARY KEY (id)) ENGINE=$engine_type;
853
eval CREATE TABLE t2(id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id) ) ENGINE=$engine_type;
754
854
INSERT INTO t1 VALUES(1);
755
855
INSERT INTO t2 VALUES(1, 1);
756
856
SELECT * from t1;
911
# Test multi update with different join methods
914
eval CREATE TABLE t1 (a int not null primary key, b int not null, key (b)) engine=$engine_type;
915
eval CREATE TABLE t2 (a int not null primary key, b int not null, key (b)) engine=$engine_type;
916
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11),(12,12);
917
INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
919
# Full join, without key
920
update t1,t2 set t1.a=t1.a+100;
924
update t1,t2 set t1.a=t1.a+100 where t1.a=101;
928
update t1,t2 set t1.b=t1.b+10 where t1.b=2;
932
update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t1.a=t2.a+100;
937
eval CREATE TABLE t2 ( NEXT_T BIGINT NOT NULL PRIMARY KEY) ENGINE=$other_non_trans_engine_type;
938
eval CREATE TABLE t1 ( B_ID INTEGER NOT NULL PRIMARY KEY) ENGINE=$engine_type;
940
INSERT INTO t1 ( B_ID ) VALUES ( 1 );
941
INSERT INTO t2 ( NEXT_T ) VALUES ( 1 );
945
eval create table t1 ( pk int primary key, parent int not null, child int not null, index (parent) ) engine = $engine_type;
946
insert into t1 values (1,0,4), (2,1,3), (3,2,1), (4,1,2);
947
select distinct parent,child from t1 order by parent;
811
951
# Test that MySQL priorities clustered indexes
813
eval create $temp table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=$engine_type;
814
eval create $temp table t2 (a int not null auto_increment primary key, b int) ENGINE = $other_engine_type;
953
eval create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=$engine_type;
954
eval create table t2 (a int not null auto_increment primary key, b int) ENGINE = $other_engine_type;
815
955
insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
816
956
insert into t2 (a) select b from t1;
817
957
insert into t1 (b) select b from t2;
843
983
# Test of UPDATE ... ORDER BY
846
eval create $temp table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=$engine_type;
986
eval create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=$engine_type;
848
988
insert into t1 (id) values (null),(null),(null),(null),(null);
849
989
update t1 set fk=69 where fk is null order by id limit 1;
850
990
SELECT * from t1;
853
eval create $temp table t1 (a int not null, b int not null, key (a)) engine=$engine_type;
993
eval create table t1 (a int not null, b int not null, key (a)) engine=$engine_type;
854
994
insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3);
856
996
update t1 set b=(@tmp:=@tmp+1) order by a;
1004
# Test of multi-table-updates (bug #1980).
1007
eval create table t1 ( c char(8) not null ) engine=$engine_type;
1008
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
1009
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
1011
alter table t1 add b char(8) not null;
1012
alter table t1 add a char(8) not null;
1013
alter table t1 add primary key (a,b,c);
1014
update t1 set a=c, b=c;
1016
eval create table t2 (c char(8) not null, b char(8) not null, a char(8) not null, primary key(a,b,c)) engine=$engine_type;
1017
insert into t2 select * from t1;
1019
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
864
1023
# test autoincrement with TRUNCATE
867
1026
SET AUTOCOMMIT=1;
868
eval create $temp table t1 (a integer auto_increment primary key) engine=$engine_type;
1027
eval create table t1 (a integer auto_increment primary key) engine=$engine_type;
869
1028
insert into t1 (a) values (NULL),(NULL);
870
1029
truncate table t1;
871
1030
insert into t1 (a) values (NULL),(NULL);
888
1047
# Test of multi updated and foreign keys
891
eval create $temp table `t1` (`id` int not null ,primary key ( `id` )) engine = $engine_type;
1050
eval create table `t1` (`id` int( 11 ) not null ,primary key ( `id` )) engine = $engine_type;
892
1051
insert into `t1`values ( 1 ) ;
893
eval create $temp table `t2` (`id` int not null default '0',unique key `id` ( `id` ) ,constraint `t1_id_fk` foreign key ( `id` ) references `t1` (`id` )) engine = $engine_type;
1052
eval create table `t2` (`id` int( 11 ) not null default '0',unique key `id` ( `id` ) ,constraint `t1_id_fk` foreign key ( `id` ) references `t1` (`id` )) engine = $engine_type;
894
1053
insert into `t2`values ( 1 ) ;
895
eval create $temp table `t3` (`id` int not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = $engine_type;
1054
eval create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = $engine_type;
896
1055
insert into `t3`values ( 1 ) ;
898
1057
delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
956
1112
INSERT INTO t1 VALUES("6", "3382", "9", "Test", NULL), ("7", "102", "5", "Le Pekin (Test)", NULL),("584", "1794", "4", "Test de resto", NULL),("837", "1822", "6", "Test 3", NULL),("1119", "3524", "1", "Societe Test", NULL),("1122", "3525", "1", "Fournisseur Test", NULL);
958
eval create $temp table t2 (
959
`id` int NOT NULL auto_increment,
960
`id_version` int NOT NULL default '1',
1114
eval CREATE TABLE t2 (
1115
`id` int(10) unsigned NOT NULL auto_increment,
1116
`id_version` int(10) unsigned NOT NULL default '1',
961
1117
PRIMARY KEY (`id`),
962
1118
KEY `id_version` (`id_version`)
963
1119
) ENGINE=$engine_type;
968
1124
(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl
969
1125
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
970
1126
drop table t1,t2;
973
1128
# Live checksum feature available + enabled
974
eval create $temp table t1 (a int, b varchar(200), c text not null) engine=$other_live_chks_engine_type;
1129
eval create table t1 (a int, b varchar(200), c text not null) checksum=1 engine=$other_live_chks_engine_type;
975
1130
# Live checksum feature available + disabled
976
eval create $temp table t2 (a int, b varchar(200), c text not null) engine=$other_live_chks_engine_type;
1131
eval create table t2 (a int, b varchar(200), c text not null) checksum=0 engine=$other_live_chks_engine_type;
978
1133
# Live checksum feature not available + enabled
979
eval create $temp table t3 (a int, b varchar(200), c varchar(200) not null) engine=$other_non_live_chks_engine_type;
1134
eval create table t3 (a int, b varchar(200), c varchar(200) not null) checksum=1 engine=$other_non_live_chks_engine_type;
980
1135
# Live checksum feature not available + disabled
981
eval create $temp table t4 (a int, b varchar(200), c varchar(200) not null) engine=$other_non_live_chks_engine_type;
1136
eval create table t4 (a int, b varchar(200), c varchar(200) not null) checksum=0 engine=$other_non_live_chks_engine_type;
983
1138
# Live checksum feature probably available + enabled
984
eval create $temp table t5 (a int, b varchar(200), c text not null) engine=$engine_type;
1139
eval create table t5 (a int, b varchar(200), c text not null) checksum=1 engine=$engine_type;
985
1140
# Live checksum feature probably available + disabled
986
eval create $temp table t6 (a int, b varchar(200), c text not null) engine=$engine_type;
1141
eval create table t6 (a int, b varchar(200), c text not null) checksum=0 engine=$engine_type;
988
1143
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
989
1144
insert t2 select * from t1;
991
1146
insert t4 select * from t1;
992
1147
insert t5 select * from t1;
993
1148
insert t6 select * from t1;
994
checksum table t1, t2, t3, t4, t5, t6, t7;
995
checksum table t1, t2, t3, t4, t5, t6, t7;
996
checksum table t1, t2, t3, t4, t5, t6, t7;
1149
checksum table t1, t2, t3, t4, t5, t6, t7 quick;
1150
checksum table t1, t2, t3, t4, t5, t6, t7;
1151
checksum table t1, t2, t3, t4, t5, t6, t7 extended;
997
1152
# #show table status;
998
1153
drop table t1,t2,t3, t4, t5, t6;
1038
1189
show create table t2;
1041
eval create $temp table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = $engine_type;
1192
eval create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = $engine_type;
1042
1193
show create table t2;
1043
1194
create unique index id on t2 (id,id2);
1044
1195
show create table t2;
1047
1198
# Check foreign key columns created in different order than key columns
1048
eval create $temp table t2 (id int not null, id2 int not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = $engine_type;
1049
show create table t2;
1052
eval create $temp table t2 (id int not null, id2 int not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = $engine_type;
1053
show create table t2;
1056
eval create $temp table t2 (id int not null, id2 int not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = $engine_type;
1057
show create table t2;
1060
eval create $temp table t2 (id int not null auto_increment, id2 int not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = $engine_type;
1061
show create table t2;
1064
eval create $temp table t2 (id int not null auto_increment, id2 int not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= $engine_type;
1199
eval create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = $engine_type;
1200
show create table t2;
1203
eval create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = $engine_type;
1204
show create table t2;
1207
eval create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = $engine_type;
1208
show create table t2;
1211
eval create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = $engine_type;
1212
show create table t2;
1215
eval create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= $engine_type;
1065
1216
show create table t2;
1066
1217
alter table t2 add index id_test (id), add index id_test2 (id,id2);
1067
1218
show create table t2;
1072
1223
# Clean up filename -- embedded server reports whole path without .frm,
1073
1224
# regular server reports relative path with .frm (argh!)
1074
--replace_result \\ / $DRIZZLE_TEST_DIR . /var/master-data/ / t2.frm t2
1225
--replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / t2.frm t2
1076
eval create $temp table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = $engine_type;
1227
eval create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = $engine_type;
1080
eval create $temp table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=$engine_type;
1231
eval create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=$engine_type;
1081
1232
show create table t2;
1083
eval create $temp table t2 (a int auto_increment primary key, b int, foreign key (b) references t1(id), foreign key (b) references t1(id), unique(b)) engine=$engine_type;
1234
eval create table t2 (a int auto_increment primary key, b int, foreign key (b) references t1(id), foreign key (b) references t1(id), unique(b)) engine=$engine_type;
1084
1235
show create table t2;
1085
1236
drop table t2, t1;
1126
1277
# Bug #6126: Duplicate columns in keys gives misleading error message
1129
eval create $temp table t1 (c char(10), index (c,c)) engine=$engine_type;
1131
eval create $temp table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=$engine_type;
1133
eval create $temp table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=$engine_type;
1135
eval create $temp table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=$engine_type;
1136
eval create $temp table t1 (c1 char(10), c2 char(10)) engine=$engine_type;
1280
eval create table t1 (c char(10), index (c,c)) engine=$engine_type;
1282
eval create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=$engine_type;
1284
eval create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=$engine_type;
1286
eval create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=$engine_type;
1287
eval create table t1 (c1 char(10), c2 char(10)) engine=$engine_type;
1138
1289
alter table t1 add key (c1,c1);
1206
1357
# Bug #13025 Server crash during filesort
1209
eval create $temp table t1 (a int not null, b int not null, c blob not null, d int not null, e int, primary key (a,b,c(255),d)) engine=$engine_type;
1360
eval create table t1 (a int not null, b int not null, c blob not null, d int not null, e int, primary key (a,b,c(255),d)) engine=$engine_type;
1210
1361
insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
1211
1362
select * from t1 order by a,b,c,d;
1212
1363
explain select * from t1 order by a,b,c,d;
1319
1468
# Clean up filename -- embedded server reports whole path without .frm,
1320
1469
# regular server reports relative path with .frm (argh!)
1321
# @TODO The below fails because it assumes latin1
1322
# as the charset. Possibly re-enable a similar test
1323
#--replace_result \\ / $DRIZZLE_TEST_DIR . /var/master-data/ / t1.frm t1
1324
#create $temp table t1 (v varchar(65530), key(v));
1326
#create $temp table t1 (v varchar(65536));
1327
#show create table t1;
1329
#create $temp table t1 (v varchar(65530) character set utf8);
1330
#show create table t1;
1333
#eval set storage_engine=$default;
1470
--replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / t1.frm t1
1471
create table t1 (v varchar(65530), key(v));
1473
create table t1 (v varchar(65536));
1474
show create table t1;
1476
create table t1 (v varchar(65530) character set utf8);
1477
show create table t1;
1480
eval set storage_engine=$default;
1335
1482
# InnoDB specific varchar tests
1336
#eval create $temp table t1 (v varchar(16384)) engine=$engine_type;
1483
eval create table t1 (v varchar(16384)) engine=$engine_type;
1340
1487
# BUG#11039 Wrong key length in min()
1343
eval create $temp table t1 (a char(1), b char(1), key(a, b)) engine=$engine_type;
1490
eval create table t1 (a char(1), b char(1), key(a, b)) engine=$engine_type;
1344
1491
insert into t1 values ('8', '6'), ('4', '7');
1345
1492
select min(a) from t1;
1346
1493
select min(b) from t1 where a='8';
1461
eval create $temp table t1 (col1 varchar(2000), index (col1(767)))
1619
eval create table t1 (col1 varchar(2000), index (col1(767)))
1462
1620
character set = latin1 engine = $engine_type;
1464
1622
# normal indexes
1465
eval create $temp table t2 (col1 char(255), index (col1))
1466
character set = latin1 engine = $engine_type;
1467
eval create $temp table t3 (col1 binary(255), index (col1))
1468
character set = latin1 engine = $engine_type;
1469
eval create $temp table t4 (col1 varchar(767), index (col1))
1470
character set = latin1 engine = $engine_type;
1471
eval create $temp table t5 (col1 varchar(767) primary key)
1472
character set = latin1 engine = $engine_type;
1473
eval create $temp table t6 (col1 varbinary(767) primary key)
1474
character set = latin1 engine = $engine_type;
1475
eval create $temp table t7 (col1 text, index(col1(767)))
1476
character set = latin1 engine = $engine_type;
1477
eval create $temp table t8 (col1 blob, index(col1(767)))
1623
eval create table t2 (col1 char(255), index (col1))
1624
character set = latin1 engine = $engine_type;
1625
eval create table t3 (col1 binary(255), index (col1))
1626
character set = latin1 engine = $engine_type;
1627
eval create table t4 (col1 varchar(767), index (col1))
1628
character set = latin1 engine = $engine_type;
1629
eval create table t5 (col1 varchar(767) primary key)
1630
character set = latin1 engine = $engine_type;
1631
eval create table t6 (col1 varbinary(767) primary key)
1632
character set = latin1 engine = $engine_type;
1633
eval create table t7 (col1 text, index(col1(767)))
1634
character set = latin1 engine = $engine_type;
1635
eval create table t8 (col1 blob, index(col1(767)))
1478
1636
character set = latin1 engine = $engine_type;
1481
1639
# multi-column indexes are allowed to be longer
1482
eval create $temp table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
1640
eval create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
1483
1641
character set = latin1 engine = $engine_type;
1485
1643
show create table t9;
1487
1645
drop table t1, t2, t3, t4, t5, t6, t7, t8, t9;
1489
1647
# these should have their index length trimmed
1490
eval create $temp table t1 (col1 varchar(768), index(col1))
1491
character set = latin1 engine = $engine_type;
1492
eval create $temp table t2 (col1 varbinary(768), index(col1))
1493
character set = latin1 engine = $engine_type;
1494
eval create $temp table t3 (col1 text, index(col1(768)))
1495
character set = latin1 engine = $engine_type;
1496
eval create $temp table t4 (col1 blob, index(col1(768)))
1648
eval create table t1 (col1 varchar(768), index(col1))
1649
character set = latin1 engine = $engine_type;
1650
eval create table t2 (col1 varbinary(768), index(col1))
1651
character set = latin1 engine = $engine_type;
1652
eval create table t3 (col1 text, index(col1(768)))
1653
character set = latin1 engine = $engine_type;
1654
eval create table t4 (col1 blob, index(col1(768)))
1497
1655
character set = latin1 engine = $engine_type;
1499
1657
show create table t1;
1512
1670
# these should be refused
1514
eval create $temp table t1 (col1 varchar(768) primary key)
1515
character set = latin1 engine = $engine_type;
1517
eval create $temp table t2 (col1 varbinary(768) primary key)
1518
character set = latin1 engine = $engine_type;
1520
eval create $temp table t3 (col1 text, primary key(col1(768)))
1521
character set = latin1 engine = $engine_type;
1523
eval create $temp table t4 (col1 blob, primary key(col1(768)))
1672
eval create table t1 (col1 varchar(768) primary key)
1673
character set = latin1 engine = $engine_type;
1675
eval create table t2 (col1 varbinary(768) primary key)
1676
character set = latin1 engine = $engine_type;
1678
eval create table t3 (col1 text, primary key(col1(768)))
1679
character set = latin1 engine = $engine_type;
1681
eval create table t4 (col1 blob, primary key(col1(768)))
1524
1682
character set = latin1 engine = $engine_type;
1630
1788
# when f_k_c is 0
1632
1790
set foreign_key_checks=0;
1633
eval create $temp table t1(a varchar(10) primary key) engine = $engine_type DEFAULT CHARSET=latin1;
1791
eval create table t1(a varchar(10) primary key) engine = $engine_type DEFAULT CHARSET=latin1;
1634
1792
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1636
eval create $temp table t2 (a varchar(10), foreign key (a) references t1(a)) engine = $engine_type DEFAULT CHARSET=utf8;
1794
eval create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = $engine_type DEFAULT CHARSET=utf8;
1637
1795
set foreign_key_checks=1;
1640
1798
# test that invalid datatype conversions with ALTER are not allowed
1642
1800
set foreign_key_checks=0;
1643
eval create $temp table t2 (a varchar(10), foreign key (a) references t1(a)) engine = $engine_type;
1644
eval create $temp table t1(a varchar(10) primary key) engine = $engine_type;
1801
eval create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = $engine_type;
1802
eval create table t1(a varchar(10) primary key) engine = $engine_type;
1645
1803
-- error 1025,1025
1646
1804
alter table t1 modify column a int;
1647
1805
set foreign_key_checks=1;
1813
1971
# Ensure that <tablename>_ibfk_0 is not mistreated as a
1814
1972
# generated foreign key identifier. (Bug #16387)
1816
eval create $temp table t1(a INT, PRIMARY KEY(a)) ENGINE=$engine_type;
1817
eval create $temp table t2(a INT) ENGINE=$engine_type;
1974
eval CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=$engine_type;
1975
eval CREATE TABLE t2(a INT) ENGINE=$engine_type;
1818
1976
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
1819
1977
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
1820
1978
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
1821
1979
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
1822
SHOW create $temp table t2;
1980
SHOW CREATE TABLE t2;
1823
1981
DROP TABLE t2,t1;
1985
# Test case for bug #16229: MySQL/InnoDB uses full explicit table locks in trigger processing
1988
connect (a,localhost,root,,);
1989
connect (b,localhost,root,,);
1991
eval create table t1(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
1992
insert into t1(a) values (1),(2),(3);
1996
update t1 set b = 5 where a = 2;
1999
create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
2003
insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
2004
(11),(21),(31),(41),(51),(61),(71),(81),(91),(101),
2005
(12),(22),(32),(42),(52),(62),(72),(82),(92),(102),
2006
(13),(23),(33),(43),(53),(63),(73),(83),(93),(103),
2007
(14),(24),(34),(44),(54),(64),(74),(84),(94),(104);
2017
# Another trigger test
2019
connect (a,localhost,root,,);
2020
connect (b,localhost,root,,);
2022
eval create table t1(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
2023
eval create table t2(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
2024
eval create table t3(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
2025
eval create table t4(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
2026
eval create table t5(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
2027
insert into t1(a) values (1),(2),(3);
2028
insert into t2(a) values (1),(2),(3);
2029
insert into t3(a) values (1),(2),(3);
2030
insert into t4(a) values (1),(2),(3);
2031
insert into t3(a) values (5),(7),(8);
2032
insert into t4(a) values (5),(7),(8);
2033
insert into t5(a) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12);
2036
create trigger t1t before insert on t1 for each row begin
2037
INSERT INTO t2 SET a = NEW.a;
2040
create trigger t2t before insert on t2 for each row begin
2041
DELETE FROM t3 WHERE a = NEW.a;
2044
create trigger t3t before delete on t3 for each row begin
2045
UPDATE t4 SET b = b + 1 WHERE a = OLD.a;
2048
create trigger t4t before update on t4 for each row begin
2049
UPDATE t5 SET b = b + 1 where a = NEW.a;
2054
update t1 set b = b + 5 where a = 1;
2055
update t2 set b = b + 5 where a = 1;
2056
update t3 set b = b + 5 where a = 1;
2057
update t4 set b = b + 5 where a = 1;
2058
insert into t5(a) values(20);
2061
insert into t1(a) values(7);
2062
insert into t2(a) values(8);
2063
delete from t2 where a = 3;
2064
update t4 set b = b + 1 where a = 3;
2070
drop table t1, t2, t3, t4, t5;
1826
2075
if ($test_foreign_keys)
1884
2133
# Bug #14360: problem with intervals
1887
eval create $temp table t1(a date) engine=$engine_type;
1888
eval create $temp table t2(a date, key(a)) engine=$engine_type;
2136
eval create table t1(a date) engine=$engine_type;
2137
eval create table t2(a date, key(a)) engine=$engine_type;
1889
2138
insert into t1 values('2005-10-01');
1890
2139
insert into t2 values('2005-10-01');
1891
2140
select * from t1, t2
1892
2141
where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
1893
2142
drop table t1, t2;
1895
eval create $temp table t1 (id int not null, f_id int not null, f int not null,
2144
eval create table t1 (id int not null, f_id int not null, f int not null,
1896
2145
primary key(f_id, id)) engine=$engine_type;
1897
eval create $temp table t2 (id int not null,s_id int not null,s varchar(200),
2146
eval create table t2 (id int not null,s_id int not null,s varchar(200),
1898
2147
primary key(id)) engine=$engine_type;
1899
2148
INSERT INTO t1 VALUES (8, 1, 3);
1900
2149
INSERT INTO t1 VALUES (1, 2, 1);
1901
2150
INSERT INTO t2 VALUES (1, 0, '');
1902
2151
INSERT INTO t2 VALUES (8, 1, '');
2153
DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id)
2154
WHERE mm.id IS NULL;
1904
2155
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
1905
2156
where mm.id is null lock in share mode;
1906
2157
drop table t1,t2;
1982
2232
connect (a,localhost,root,,);
1983
2233
connect (b,localhost,root,,);
1985
eval create $temp table t1(a int not null, b int, primary key(a)) engine=$engine_type;
2235
eval create table t1(a int not null, b int, primary key(a)) engine=$engine_type;
1986
2236
insert into t1 values (1,2),(5,3),(4,2);
1987
eval create $temp table t2(d int not null, e int, primary key(d)) engine=$engine_type;
2237
eval create table t2(d int not null, e int, primary key(d)) engine=$engine_type;
1988
2238
insert into t2 values (8,6),(12,1),(3,1);
1990
2240
set autocommit = 0;
2038
2288
connect (j,localhost,root,,);
2039
2289
eval SET SESSION STORAGE_ENGINE = $engine_type;
2041
create $temp table t1(a int not null, b int, primary key(a));
2291
create table t1(a int not null, b int, primary key(a));
2042
2292
insert into t1 values (1,2),(5,3),(4,2);
2043
create $temp table t2(a int not null, b int, primary key(a));
2293
create table t2(a int not null, b int, primary key(a));
2044
2294
insert into t2 values (8,6),(12,1),(3,1);
2045
create $temp table t3(d int not null, b int, primary key(d));
2295
create table t3(d int not null, b int, primary key(d));
2046
2296
insert into t3 values (8,6),(12,1),(3,1);
2047
create $temp table t5(a int not null, b int, primary key(a));
2297
create table t5(a int not null, b int, primary key(a));
2048
2298
insert into t5 values (1,2),(5,3),(4,2);
2049
create $temp table t6(d int not null, e int, primary key(d));
2299
create table t6(d int not null, e int, primary key(d));
2050
2300
insert into t6 values (8,6),(12,1),(3,1);
2051
create $temp table t8(a int not null, b int, primary key(a));
2301
create table t8(a int not null, b int, primary key(a));
2052
2302
insert into t8 values (1,2),(5,3),(4,2);
2053
create $temp table t9(d int not null, e int, primary key(d));
2303
create table t9(d int not null, e int, primary key(d));
2054
2304
insert into t9 values (8,6),(12,1),(3,1);
2056
2306
set autocommit = 0;