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;
749
749
insert into t1 values (1,'one','one value',101),
750
750
(2,'two','two value',102),(3,'three','three value',103);
752
751
replace into t1 (value,name,uid) values ('other value','two',102);
753
752
delete from t1 where uid=102;
755
753
replace into t1 (value,name,uid) values ('other value','two',102);
757
754
replace into t1 (value,name,uid) values ('other value','two',102);
758
755
select * from t1;
759
756
id name value uid
760
757
1 one one value 101
758
6 two other value 102
761
759
3 three three value 103
762
6 two other value 102
764
761
create database mysqltest;
765
762
create table mysqltest.t1 (a int not null) engine= MyISAM;
832
829
create table t1 (t int not null default 1, key (t)) engine=MyISAM;
834
831
Field Type Null Key Default Extra
837
834
CREATE TABLE t1 (
838
number bigint(20) NOT NULL default '0',
835
number bigint NOT NULL default '0',
839
836
cname char(15) NOT NULL default '',
840
carrier_id smallint(6) NOT NULL default '0',
841
privacy tinyint(4) NOT NULL default '0',
837
carrier_id int NOT NULL default '0',
838
privacy int NOT NULL default '0',
842
839
last_mod_date timestamp NOT NULL,
843
last_mod_id smallint(6) NOT NULL default '0',
840
last_mod_id int NOT NULL default '0',
844
841
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'
842
last_app_id int default '-1',
843
version int NOT NULL default '0',
844
assigned_scps int default '0',
845
status int default '0'
850
847
INSERT INTO t1 VALUES (4077711111,'SeanWheeler',90,2,20020111112846,500,00000000000000,-1,2,3,1);
851
848
INSERT INTO t1 VALUES (9197722223,'berry',90,3,20020111112809,500,20020102114532,501,4,10,0);
854
851
INSERT INTO t1 VALUES (6014911113,'SudzCarwash',520,1,20020102115234,500,20020102115259,501,33,32768,0);
855
852
INSERT INTO t1 VALUES (333,'tubs',99,2,20020109113440,501,20020109113440,500,3,10,0);
856
853
CREATE TABLE t2 (
857
number bigint(20) NOT NULL default '0',
854
number bigint NOT NULL default '0',
858
855
cname char(15) NOT NULL default '',
859
carrier_id smallint(6) NOT NULL default '0',
860
privacy tinyint(4) NOT NULL default '0',
856
carrier_id int NOT NULL default '0',
857
privacy int NOT NULL default '0',
861
858
last_mod_date timestamp NOT NULL,
862
last_mod_id smallint(6) NOT NULL default '0',
859
last_mod_id int NOT NULL default '0',
863
860
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'
861
last_app_id int default '-1',
862
version int NOT NULL default '0',
863
assigned_scps int default '0',
864
status int default '0'
869
866
INSERT INTO t2 VALUES (4077711111,'SeanWheeler',0,2,20020111112853,500,00000000000000,-1,2,3,1);
870
867
INSERT INTO t2 VALUES (9197722223,'berry',90,3,20020111112818,500,20020102114532,501,4,10,0);
1171
1168
insert into t1 (a) values (NULL),(NULL);
1172
1169
SELECT * from t1;
1177
CREATE TABLE t1 (col1 int(1))ENGINE=MyISAM;
1178
CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP,INDEX stamp_idx
1174
CREATE TABLE t1 (col1 int)ENGINE=MyISAM;
1175
CREATE TABLE t2 (col1 int,stamp TIMESTAMP,INDEX stamp_idx
1179
1176
(stamp))ENGINE=MyISAM;
1180
1177
insert into t1 values (1),(2),(3);
1181
1178
insert into t2 values (1, 20020204130000),(2, 20020204130000),(4,20020204310000 ),(5,20020204230000);
1183
Warning 1265 Data truncated for column 'stamp' at row 3
1179
ERROR 22007: Incorrect datetime value: '20020204310000' for column 'stamp' at row 3
1184
1180
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
1185
1181
'20020204120000' GROUP BY col1;
1191
1186
drop table t1,t2;
1192
1187
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',
1188
`id` int NOT NULL auto_increment,
1189
`id_object` int default '0',
1190
`id_version` int NOT NULL default '1',
1196
1191
`label` varchar(100) NOT NULL default '',
1197
1192
`description` text,
1198
1193
PRIMARY KEY (`id`),
1201
1196
) ENGINE=MyISAM;
1202
1197
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
1198
CREATE TABLE t2 (
1204
`id` int(10) unsigned NOT NULL auto_increment,
1205
`id_version` int(10) unsigned NOT NULL default '1',
1199
`id` int NOT NULL auto_increment,
1200
`id_version` int NOT NULL default '1',
1206
1201
PRIMARY KEY (`id`),
1207
1202
KEY `id_version` (`id_version`)
1208
1203
) ENGINE=MyISAM;
1418
1404
Note 1265 Data truncated for column 'c' at row 1
1419
1405
select concat('*',v,'*',c,'*',t,'*') from t1;
1420
1406
concat('*',v,'*',c,'*',t,'*')
1423
1409
show create table t1;
1424
1410
Table Create Table
1425
1411
t1 CREATE TABLE `t1` (
1426
1412
`v` varchar(10) DEFAULT NULL,
1427
`c` char(10) DEFAULT NULL,
1413
`c` varchar(10) DEFAULT NULL,
1429
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1430
1416
create table t2 like t1;
1431
1417
show create table t2;
1432
1418
Table Create Table
1433
1419
t2 CREATE TABLE `t2` (
1434
1420
`v` varchar(10) DEFAULT NULL,
1435
`c` char(10) DEFAULT NULL,
1421
`c` varchar(10) DEFAULT NULL,
1437
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1438
1424
create table t3 select * from t1;
1439
1425
show create table t3;
1440
1426
Table Create Table
1441
1427
t3 CREATE TABLE `t3` (
1442
1428
`v` varchar(10) DEFAULT NULL,
1443
`c` char(10) DEFAULT NULL,
1429
`c` varchar(10) DEFAULT NULL,
1445
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1446
1432
alter table t1 modify c varchar(10);
1447
1433
show create table t1;
1448
1434
Table Create Table
1450
1436
`v` varchar(10) DEFAULT NULL,
1451
1437
`c` varchar(10) DEFAULT NULL,
1453
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1454
1440
alter table t1 modify v char(10);
1455
1441
show create table t1;
1456
1442
Table Create Table
1457
1443
t1 CREATE TABLE `t1` (
1458
`v` char(10) DEFAULT NULL,
1444
`v` varchar(10) DEFAULT NULL,
1459
1445
`c` varchar(10) DEFAULT NULL,
1461
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1462
1448
alter table t1 modify t varchar(10);
1464
1450
Note 1265 Data truncated for column 't' at row 2
1465
1451
show create table t1;
1466
1452
Table Create Table
1467
1453
t1 CREATE TABLE `t1` (
1468
`v` char(10) DEFAULT NULL,
1454
`v` varchar(10) DEFAULT NULL,
1469
1455
`c` varchar(10) DEFAULT NULL,
1470
1456
`t` varchar(10) DEFAULT NULL
1471
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1472
1458
select concat('*',v,'*',c,'*',t,'*') from t1;
1473
1459
concat('*',v,'*',c,'*',t,'*')
1476
1462
drop table t1,t2,t3;
1477
1463
create table t1 (v varchar(10), c char(10), t text, key(v), key(c), key(t(10)));
1478
1464
show create table t1;
1479
1465
Table Create Table
1480
1466
t1 CREATE TABLE `t1` (
1481
1467
`v` varchar(10) DEFAULT NULL,
1482
`c` char(10) DEFAULT NULL,
1468
`c` varchar(10) DEFAULT NULL,
1487
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1488
1474
select count(*) from t1;
1528
1514
explain select count(*) from t1 where v='a ';
1529
1515
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
1516
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1531
1517
explain select count(*) from t1 where c='a ';
1532
1518
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
1519
1 SIMPLE t1 ref c c 43 const # Using where; Using index
1534
1520
explain select count(*) from t1 where t='a ';
1535
1521
id select_type table type possible_keys key key_len ref rows Extra
1536
1 SIMPLE t1 ref t t 13 const # Using where
1522
1 SIMPLE t1 ref t t 43 const # Using where
1537
1523
explain select count(*) from t1 where v like 'a%';
1538
1524
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
1525
1 SIMPLE t1 range v v 43 NULL # Using where; Using index
1540
1526
explain select count(*) from t1 where v between 'a' and 'a ';
1541
1527
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
1528
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1543
1529
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1544
1530
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
1531
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1546
1532
alter table t1 add unique(v);
1547
1533
ERROR 23000: Duplicate entry '{ ' for key 'v_2'
1548
1534
alter table t1 add key(v);
1549
1535
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
1561
1547
explain select * from t1 where v='a';
1562
1548
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
1549
1 SIMPLE t1 ref v,v_2 # 43 const # Using where
1564
1550
select v,count(*) from t1 group by v limit 10;
1725
1711
explain select count(*) from t1 where v='a ';
1726
1712
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
1713
1 SIMPLE t1 ref v v 1203 const # Using where; Using index
1728
1714
explain select count(*) from t1 where v like 'a%';
1729
1715
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
1716
1 SIMPLE t1 range v v 1203 NULL # Using where; Using index
1731
1717
explain select count(*) from t1 where v between 'a' and 'a ';
1732
1718
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
1719
1 SIMPLE t1 ref v v 1203 const # Using where; Using index
1734
1720
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1735
1721
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
1722
1 SIMPLE t1 ref v v 1203 const # Using where; Using index
1737
1723
explain select * from t1 where v='a';
1738
1724
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
1725
1 SIMPLE t1 ref v v 1203 const # Using where
1740
1726
select v,count(*) from t1 group by v limit 10;
1805
1791
explain select count(*) from t1 where v='a ';
1806
1792
id select_type table type possible_keys key key_len ref rows Extra
1807
1 SIMPLE t1 ref v v 33 const # Using where
1793
1 SIMPLE t1 ref v v 123 const # Using where
1808
1794
explain select count(*) from t1 where v like 'a%';
1809
1795
id select_type table type possible_keys key key_len ref rows Extra
1810
1 SIMPLE t1 range v v 33 NULL # Using where
1796
1 SIMPLE t1 range v v 123 NULL # Using where
1811
1797
explain select count(*) from t1 where v between 'a' and 'a ';
1812
1798
id select_type table type possible_keys key key_len ref rows Extra
1813
1 SIMPLE t1 ref v v 33 const # Using where
1799
1 SIMPLE t1 ref v v 123 const # Using where
1814
1800
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1815
1801
id select_type table type possible_keys key key_len ref rows Extra
1816
1 SIMPLE t1 ref v v 33 const # Using where
1802
1 SIMPLE t1 ref v v 123 const # Using where
1817
1803
explain select * from t1 where v='a';
1818
1804
id select_type table type possible_keys key key_len ref rows Extra
1819
1 SIMPLE t1 ref v v 33 const # Using where
1805
1 SIMPLE t1 ref v v 123 const # Using where
1820
1806
select v,count(*) from t1 group by v limit 10;
1936
1926
Table Create Table
1937
1927
t1 CREATE TABLE `t1` (
1938
1928
`v` varchar(10) DEFAULT NULL,
1939
`c` char(10) DEFAULT NULL,
1929
`c` varchar(10) DEFAULT NULL,
1944
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1946
create table t1 (v char(10) character set utf8);
1936
create table t1 (v char(10));
1947
1937
show create table t1;
1948
1938
Table Create Table
1949
1939
t1 CREATE TABLE `t1` (
1950
`v` char(10) CHARACTER SET utf8 DEFAULT NULL
1951
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1940
`v` varchar(10) DEFAULT NULL
1953
1943
create table t1 (v varchar(10), c char(10)) row_format=fixed;
1954
1944
show create table t1;
1955
1945
Table Create Table
1956
1946
t1 CREATE TABLE `t1` (
1957
1947
`v` varchar(10) DEFAULT NULL,
1958
`c` char(10) DEFAULT NULL
1959
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED
1948
`c` varchar(10) DEFAULT NULL
1949
) ENGINE=MyISAM ROW_FORMAT=FIXED
1960
1950
insert into t1 values('a','a'),('a ','a ');
1961
1951
select concat('*',v,'*',c,'*') from t1;
1962
1952
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
1956
create table t1(a int, b varchar(12), key ba(b, a));
1973
1957
insert into t1 values (1, 'A'), (20, NULL);
1974
1958
explain select * from t1 where a=20 and b is null;
1975
1959
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
1960
1 SIMPLE t1 ref ba ba 56 const,const 1 Using where; Using index
1977
1961
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
1965
create table t1 (a char(1), b char(1), key(a, b)) engine=MyISAM;
2007
1966
insert into t1 values ('8', '6'), ('4', '7');
2008
1967
select min(a) from t1;
2059
2018
select * from t1;
2061
2020
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
2021
create table t1(a date) engine=MyISAM;
2121
2022
create table t2(a date, key(a)) engine=MyISAM;
2122
2023
insert into t1 values('2005-10-01');