1
1
SET SESSION STORAGE_ENGINE = MEMORY;
2
2
drop table if exists t1,t2,t3,t4;
3
3
drop database if exists mysqltest;
4
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=MyISAM;
4
create 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=MyISAM;
5
5
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
6
6
select id, code, name from t1 order by id;
143
143
explain select level from t1 where level=1;
144
144
id select_type table type possible_keys key key_len ref rows Extra
145
1 SIMPLE t1 ref level level 1 const # Using index
145
1 SIMPLE t1 ref level level 4 const # Using index
146
146
explain select level,id from t1 where level=1;
147
147
id select_type table type possible_keys key key_len ref rows Extra
148
1 SIMPLE t1 ref level level 1 const #
148
1 SIMPLE t1 ref level level 4 const #
149
149
explain select level,id,parent_id from t1 where level=1;
150
150
id select_type table type possible_keys key key_len ref rows Extra
151
1 SIMPLE t1 ref level level 1 const #
151
1 SIMPLE t1 ref level level 4 const #
152
152
select level,id from t1 where level=1;
832
832
create table t1 (t int not null default 1, key (t)) engine=MyISAM;
834
834
Field Type Null Key Default Extra
837
837
CREATE TABLE t1 (
838
number bigint(20) NOT NULL default '0',
838
number bigint NOT NULL default '0',
839
839
cname char(15) NOT NULL default '',
840
carrier_id smallint(6) NOT NULL default '0',
841
privacy tinyint(4) NOT NULL default '0',
840
carrier_id int NOT NULL default '0',
841
privacy int NOT NULL default '0',
842
842
last_mod_date timestamp NOT NULL,
843
last_mod_id smallint(6) NOT NULL default '0',
843
last_mod_id int NOT NULL default '0',
844
844
last_app_date timestamp NOT NULL,
845
last_app_id smallint(6) default '-1',
846
version smallint(6) NOT NULL default '0',
847
assigned_scps int(11) default '0',
848
status tinyint(4) default '0'
845
last_app_id int default '-1',
846
version int NOT NULL default '0',
847
assigned_scps int default '0',
848
status int default '0'
850
850
INSERT INTO t1 VALUES (4077711111,'SeanWheeler',90,2,20020111112846,500,00000000000000,-1,2,3,1);
851
851
INSERT INTO t1 VALUES (9197722223,'berry',90,3,20020111112809,500,20020102114532,501,4,10,0);
854
854
INSERT INTO t1 VALUES (6014911113,'SudzCarwash',520,1,20020102115234,500,20020102115259,501,33,32768,0);
855
855
INSERT INTO t1 VALUES (333,'tubs',99,2,20020109113440,501,20020109113440,500,3,10,0);
856
856
CREATE TABLE t2 (
857
number bigint(20) NOT NULL default '0',
857
number bigint NOT NULL default '0',
858
858
cname char(15) NOT NULL default '',
859
carrier_id smallint(6) NOT NULL default '0',
860
privacy tinyint(4) NOT NULL default '0',
859
carrier_id int NOT NULL default '0',
860
privacy int NOT NULL default '0',
861
861
last_mod_date timestamp NOT NULL,
862
last_mod_id smallint(6) NOT NULL default '0',
862
last_mod_id int NOT NULL default '0',
863
863
last_app_date timestamp NOT NULL,
864
last_app_id smallint(6) default '-1',
865
version smallint(6) NOT NULL default '0',
866
assigned_scps int(11) default '0',
867
status tinyint(4) default '0'
864
last_app_id int default '-1',
865
version int NOT NULL default '0',
866
assigned_scps int default '0',
867
status int default '0'
869
869
INSERT INTO t2 VALUES (4077711111,'SeanWheeler',0,2,20020111112853,500,00000000000000,-1,2,3,1);
870
870
INSERT INTO t2 VALUES (9197722223,'berry',90,3,20020111112818,500,20020102114532,501,4,10,0);
1171
1171
insert into t1 (a) values (NULL),(NULL);
1172
1172
SELECT * from t1;
1177
CREATE TABLE t1 (col1 int(1))ENGINE=MyISAM;
1178
CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP,INDEX stamp_idx
1177
CREATE TABLE t1 (col1 int)ENGINE=MyISAM;
1178
CREATE TABLE t2 (col1 int,stamp TIMESTAMP,INDEX stamp_idx
1179
1179
(stamp))ENGINE=MyISAM;
1180
1180
insert into t1 values (1),(2),(3);
1181
1181
insert into t2 values (1, 20020204130000),(2, 20020204130000),(4,20020204310000 ),(5,20020204230000);
1183
Warning 1265 Data truncated for column 'stamp' at row 3
1182
ERROR 22007: Incorrect datetime value: '20020204310000' for column 'stamp' at row 3
1184
1183
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
1185
1184
'20020204120000' GROUP BY col1;
1191
1189
drop table t1,t2;
1192
1190
CREATE TABLE t1 (
1193
`id` int(10) unsigned NOT NULL auto_increment,
1194
`id_object` int(10) unsigned default '0',
1195
`id_version` int(10) unsigned NOT NULL default '1',
1191
`id` int NOT NULL auto_increment,
1192
`id_object` int default '0',
1193
`id_version` int NOT NULL default '1',
1196
1194
`label` varchar(100) NOT NULL default '',
1197
1195
`description` text,
1198
1196
PRIMARY KEY (`id`),
1201
1199
) ENGINE=MyISAM;
1202
1200
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);
1203
1201
CREATE TABLE t2 (
1204
`id` int(10) unsigned NOT NULL auto_increment,
1205
`id_version` int(10) unsigned NOT NULL default '1',
1202
`id` int NOT NULL auto_increment,
1203
`id_version` int NOT NULL default '1',
1206
1204
PRIMARY KEY (`id`),
1207
1205
KEY `id_version` (`id_version`)
1208
1206
) ENGINE=MyISAM;
1418
1413
Note 1265 Data truncated for column 'c' at row 1
1419
1414
select concat('*',v,'*',c,'*',t,'*') from t1;
1420
1415
concat('*',v,'*',c,'*',t,'*')
1423
1418
show create table t1;
1424
1419
Table Create Table
1425
1420
t1 CREATE TABLE `t1` (
1426
`v` varchar(10) DEFAULT NULL,
1427
`c` char(10) DEFAULT NULL,
1429
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1430
1425
create table t2 like t1;
1431
1426
show create table t2;
1432
1427
Table Create Table
1433
1428
t2 CREATE TABLE `t2` (
1434
`v` varchar(10) DEFAULT NULL,
1435
`c` char(10) DEFAULT NULL,
1437
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1438
1433
create table t3 select * from t1;
1439
1434
show create table t3;
1440
1435
Table Create Table
1441
1436
t3 CREATE TABLE `t3` (
1442
`v` varchar(10) DEFAULT NULL,
1443
`c` char(10) DEFAULT NULL,
1445
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1446
1441
alter table t1 modify c varchar(10);
1447
1442
show create table t1;
1448
1443
Table Create Table
1449
1444
t1 CREATE TABLE `t1` (
1450
`v` varchar(10) DEFAULT NULL,
1451
`c` varchar(10) DEFAULT NULL,
1453
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1454
1449
alter table t1 modify v char(10);
1455
1450
show create table t1;
1456
1451
Table Create Table
1457
1452
t1 CREATE TABLE `t1` (
1458
`v` char(10) DEFAULT NULL,
1459
`c` varchar(10) DEFAULT NULL,
1461
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1462
1457
alter table t1 modify t varchar(10);
1464
1459
Note 1265 Data truncated for column 't' at row 2
1465
1460
show create table t1;
1466
1461
Table Create Table
1467
1462
t1 CREATE TABLE `t1` (
1468
`v` char(10) DEFAULT NULL,
1469
`c` varchar(10) DEFAULT NULL,
1470
`t` varchar(10) DEFAULT NULL
1471
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1472
1467
select concat('*',v,'*',c,'*',t,'*') from t1;
1473
1468
concat('*',v,'*',c,'*',t,'*')
1476
1471
drop table t1,t2,t3;
1477
1472
create table t1 (v varchar(10), c char(10), t text, key(v), key(c), key(t(10)));
1478
1473
show create table t1;
1479
1474
Table Create Table
1480
1475
t1 CREATE TABLE `t1` (
1481
`v` varchar(10) DEFAULT NULL,
1482
`c` char(10) DEFAULT NULL,
1487
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1488
1483
select count(*) from t1;
1528
1523
explain select count(*) from t1 where v='a ';
1529
1524
id select_type table type possible_keys key key_len ref rows Extra
1530
1 SIMPLE t1 ref v v 13 const # Using where; Using index
1525
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1531
1526
explain select count(*) from t1 where c='a ';
1532
1527
id select_type table type possible_keys key key_len ref rows Extra
1533
1 SIMPLE t1 ref c c 11 const # Using where; Using index
1528
1 SIMPLE t1 ref c c 43 const # Using where; Using index
1534
1529
explain select count(*) from t1 where t='a ';
1535
1530
id select_type table type possible_keys key key_len ref rows Extra
1536
1 SIMPLE t1 ref t t 13 const # Using where
1531
1 SIMPLE t1 ref t t 43 const # Using where
1537
1532
explain select count(*) from t1 where v like 'a%';
1538
1533
id select_type table type possible_keys key key_len ref rows Extra
1539
1 SIMPLE t1 range v v 13 NULL # Using where; Using index
1534
1 SIMPLE t1 range v v 43 NULL # Using where; Using index
1540
1535
explain select count(*) from t1 where v between 'a' and 'a ';
1541
1536
id select_type table type possible_keys key key_len ref rows Extra
1542
1 SIMPLE t1 ref v v 13 const # Using where; Using index
1537
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1543
1538
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1544
1539
id select_type table type possible_keys key key_len ref rows Extra
1545
1 SIMPLE t1 ref v v 13 const # Using where; Using index
1540
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1546
1541
alter table t1 add unique(v);
1547
1542
ERROR 23000: Duplicate entry '{ ' for key 'v_2'
1548
1543
alter table t1 add key(v);
1549
1544
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
1561
1556
explain select * from t1 where v='a';
1562
1557
id select_type table type possible_keys key key_len ref rows Extra
1563
1 SIMPLE t1 ref v,v_2 # 13 const # Using index condition
1558
1 SIMPLE t1 ref v,v_2 # 43 const # Using where
1564
1559
select v,count(*) from t1 group by v limit 10;
1725
1720
explain select count(*) from t1 where v='a ';
1726
1721
id select_type table type possible_keys key key_len ref rows Extra
1727
1 SIMPLE t1 ref v v 303 const # Using where; Using index
1722
1 SIMPLE t1 ref v v 1203 const # Using where; Using index
1728
1723
explain select count(*) from t1 where v like 'a%';
1729
1724
id select_type table type possible_keys key key_len ref rows Extra
1730
1 SIMPLE t1 range v v 303 NULL # Using where; Using index
1725
1 SIMPLE t1 range v v 1203 NULL # Using where; Using index
1731
1726
explain select count(*) from t1 where v between 'a' and 'a ';
1732
1727
id select_type table type possible_keys key key_len ref rows Extra
1733
1 SIMPLE t1 ref v v 303 const # Using where; Using index
1728
1 SIMPLE t1 ref v v 1203 const # Using where; Using index
1734
1729
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1735
1730
id select_type table type possible_keys key key_len ref rows Extra
1736
1 SIMPLE t1 ref v v 303 const # Using where; Using index
1731
1 SIMPLE t1 ref v v 1203 const # Using where; Using index
1737
1732
explain select * from t1 where v='a';
1738
1733
id select_type table type possible_keys key key_len ref rows Extra
1739
1 SIMPLE t1 ref v v 303 const # Using index condition
1734
1 SIMPLE t1 ref v v 1203 const # Using where
1740
1735
select v,count(*) from t1 group by v limit 10;
1805
1800
explain select count(*) from t1 where v='a ';
1806
1801
id select_type table type possible_keys key key_len ref rows Extra
1807
1 SIMPLE t1 ref v v 33 const # Using where
1802
1 SIMPLE t1 ref v v 123 const # Using where
1808
1803
explain select count(*) from t1 where v like 'a%';
1809
1804
id select_type table type possible_keys key key_len ref rows Extra
1810
1 SIMPLE t1 range v v 33 NULL # Using where
1805
1 SIMPLE t1 range v v 123 NULL # Using where
1811
1806
explain select count(*) from t1 where v between 'a' and 'a ';
1812
1807
id select_type table type possible_keys key key_len ref rows Extra
1813
1 SIMPLE t1 ref v v 33 const # Using where
1808
1 SIMPLE t1 ref v v 123 const # Using where
1814
1809
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1815
1810
id select_type table type possible_keys key key_len ref rows Extra
1816
1 SIMPLE t1 ref v v 33 const # Using where
1811
1 SIMPLE t1 ref v v 123 const # Using where
1817
1812
explain select * from t1 where v='a';
1818
1813
id select_type table type possible_keys key key_len ref rows Extra
1819
1 SIMPLE t1 ref v v 33 const # Using where
1814
1 SIMPLE t1 ref v v 123 const # Using where
1820
1815
select v,count(*) from t1 group by v limit 10;
1935
1934
show create table t1;
1936
1935
Table Create Table
1937
1936
t1 CREATE TABLE `t1` (
1938
`v` varchar(10) DEFAULT NULL,
1939
`c` char(10) DEFAULT NULL,
1944
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1946
create table t1 (v char(10) character set utf8);
1945
create table t1 (v char(10));
1947
1946
show create table t1;
1948
1947
Table Create Table
1949
1948
t1 CREATE TABLE `t1` (
1950
`v` char(10) CHARACTER SET utf8 DEFAULT NULL
1951
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1953
1952
create table t1 (v varchar(10), c char(10)) row_format=fixed;
1954
1953
show create table t1;
1955
1954
Table Create Table
1956
1955
t1 CREATE TABLE `t1` (
1957
`v` varchar(10) DEFAULT NULL,
1958
`c` char(10) DEFAULT NULL
1959
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED
1958
) ENGINE=MyISAM ROW_FORMAT=FIXED
1960
1959
insert into t1 values('a','a'),('a ','a ');
1961
1960
select concat('*',v,'*',c,'*') from t1;
1962
1961
concat('*',v,'*',c,'*')
1966
create table t1 (v varchar(65530), key(v(10)));
1967
insert into t1 values(repeat('a',65530));
1968
select length(v) from t1 where v=repeat('a',65530);
1972
1965
create table t1(a int, b varchar(12), key ba(b, a));
1973
1966
insert into t1 values (1, 'A'), (20, NULL);
1974
1967
explain select * from t1 where a=20 and b is null;
1975
1968
id select_type table type possible_keys key key_len ref rows Extra
1976
1 SIMPLE t1 ref ba ba 20 const,const 1 Using where; Using index
1969
1 SIMPLE t1 ref ba ba 56 const,const 1 Using where; Using index
1977
1970
select * from t1 where a=20 and b is null;
1981
create table t1 (v varchar(65530), key(v));
1983
Warning 1071 Specified key was too long; max key length is 1332 bytes
1985
create table t1 (v varchar(65536));
1987
Note 1246 Converting column 'v' from VARCHAR to TEXT
1988
show create table t1;
1990
t1 CREATE TABLE `t1` (
1992
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1994
create table t1 (v varchar(65530) character set utf8);
1996
Note 1246 Converting column 'v' from VARCHAR to TEXT
1997
show create table t1;
1999
t1 CREATE TABLE `t1` (
2000
`v` mediumtext CHARACTER SET utf8
2001
) ENGINE=MyISAM DEFAULT CHARSET=latin1
2003
set storage_engine=MEMORY;
2004
create table t1 (v varchar(16384)) engine=MyISAM;
2006
1974
create table t1 (a char(1), b char(1), key(a, b)) engine=MyISAM;
2007
1975
insert into t1 values ('8', '6'), ('4', '7');
2008
1976
select min(a) from t1;
2059
2027
select * from t1;
2061
2029
drop table t1,t2;
2062
create table t1(a int not null, b int, c int, d int, primary key(a)) engine=MyISAM;
2063
insert into t1(a) values (1),(2),(3);
2066
update t1 set b = 5 where a = 2;
2067
create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
2069
insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
2070
(11),(21),(31),(41),(51),(61),(71),(81),(91),(101),
2071
(12),(22),(32),(42),(52),(62),(72),(82),(92),(102),
2072
(13),(23),(33),(43),(53),(63),(73),(83),(93),(103),
2073
(14),(24),(34),(44),(54),(64),(74),(84),(94),(104);
2078
create table t1(a int not null, b int, c int, d int, primary key(a)) engine=MyISAM;
2079
create table t2(a int not null, b int, c int, d int, primary key(a)) engine=MyISAM;
2080
create table t3(a int not null, b int, c int, d int, primary key(a)) engine=MyISAM;
2081
create table t4(a int not null, b int, c int, d int, primary key(a)) engine=MyISAM;
2082
create table t5(a int not null, b int, c int, d int, primary key(a)) engine=MyISAM;
2083
insert into t1(a) values (1),(2),(3);
2084
insert into t2(a) values (1),(2),(3);
2085
insert into t3(a) values (1),(2),(3);
2086
insert into t4(a) values (1),(2),(3);
2087
insert into t3(a) values (5),(7),(8);
2088
insert into t4(a) values (5),(7),(8);
2089
insert into t5(a) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12);
2090
create trigger t1t before insert on t1 for each row begin
2091
INSERT INTO t2 SET a = NEW.a;
2093
create trigger t2t before insert on t2 for each row begin
2094
DELETE FROM t3 WHERE a = NEW.a;
2096
create trigger t3t before delete on t3 for each row begin
2097
UPDATE t4 SET b = b + 1 WHERE a = OLD.a;
2099
create trigger t4t before update on t4 for each row begin
2100
UPDATE t5 SET b = b + 1 where a = NEW.a;
2104
update t1 set b = b + 5 where a = 1;
2105
update t2 set b = b + 5 where a = 1;
2106
update t3 set b = b + 5 where a = 1;
2107
update t4 set b = b + 5 where a = 1;
2108
insert into t5(a) values(20);
2110
insert into t1(a) values(7);
2111
insert into t2(a) values(8);
2112
delete from t2 where a = 3;
2113
update t4 set b = b + 1 where a = 3;
2119
drop table t1, t2, t3, t4, t5;
2120
2030
create table t1(a date) engine=MyISAM;
2121
2031
create table t2(a date, key(a)) engine=MyISAM;
2122
2032
insert into t1 values('2005-10-01');