1
drop table if exists t1,t2,t3;
5
name CHAR(32) NOT NULL,
7
INDEX indexIDname (ID(8),name(8))
10
('keyword','indexdir','/export/home/local/www/database/indexes/keyword');
11
INSERT INTO t1 VALUES ('keyword','urlprefix','text/ /text');
12
INSERT INTO t1 VALUES ('keyword','urlmap','/text/ /');
13
INSERT INTO t1 VALUES ('keyword','attr','personal employee company');
15
('emailgids','indexdir','/export/home/local/www/database/indexes/emailgids');
16
INSERT INTO t1 VALUES ('emailgids','urlprefix','text/ /text');
17
INSERT INTO t1 VALUES ('emailgids','urlmap','/text/ /');
18
INSERT INTO t1 VALUES ('emailgids','attr','personal employee company');
19
SELECT value FROM t1 WHERE ID='emailgids' AND name='attr';
21
personal employee company
24
price int DEFAULT '0' NOT NULL,
25
area varchar(160) DEFAULT '' NOT NULL,
26
type varchar(160) DEFAULT '' NOT NULL,
27
transityes enum('Y','N') DEFAULT 'Y' NOT NULL,
28
shopsyes enum('Y','N') DEFAULT 'Y' NOT NULL,
29
schoolsyes enum('Y','N') DEFAULT 'Y' NOT NULL,
30
petsyes enum('Y','N') DEFAULT 'Y' NOT NULL,
31
KEY price (price,area,type,transityes,shopsyes,schoolsyes,petsyes)
33
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','N','N','N','N');
34
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','N','N','N','N');
35
INSERT INTO t1 (price, area, type) VALUES (900,'Vancouver','Shared/Roomate');
36
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y');
37
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y');
38
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y');
39
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y');
40
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y');
41
SELECT * FROM t1 WHERE area='Vancouver' and transityes='y' and schoolsyes='y' and ( ((type='1 Bedroom' or type='Studio/Bach') and (price<=500)) or ((type='2 Bedroom') and (price<=550)) or ((type='Shared/Roomate') and (price<=300)) or ((type='Room and Board') and (price<=500)) ) and price <= 400;
42
price area type transityes shopsyes schoolsyes petsyes
44
CREATE TABLE t1 (program enum('signup','unique','sliding') not null, type enum('basic','sliding','signup'), PRIMARY KEY (program));
45
ALTER TABLE t1 modify program enum('signup','unique','sliding');
48
name varchar(50) DEFAULT '' NOT NULL,
49
author varchar(50) DEFAULT '' NOT NULL,
50
category decimal(10,0) DEFAULT '0' NOT NULL,
58
timeout decimal(10,0),
60
creation decimal(10,0),
61
livinguntil decimal(10,0),
65
subtype decimal(10,0),
68
capacity decimal(10,0),
70
CCident varchar(50) DEFAULT '' NOT NULL,
71
PRIMARY KEY (name,author,category)
74
('patnom','patauteur',0,'p.favre@cryo-networks.fr',NULL,NULL,'#p2sndnq6ae5g1u6t','essai salut','scol://195.242.78.119:patauteur.patnom',NULL,NULL,NULL,950036174,-882087474,NULL,3,0,3,'1','Pub/patnom/futur_divers.scs',NULL,'pat','CC1');
76
('LeNomDeMonSite','Marc',0,'m.barilley@cryo-networks.fr',NULL,NULL,NULL,NULL,'scol://195.242.78.119:Marc.LeNomDeMonSite',NULL,NULL,NULL,950560434,-881563214,NULL,3,0,3,'1','Pub/LeNomDeMonSite/domus_hibere.scs',NULL,'Marq','CC1');
77
select * from t1 where name='patnom' and author='patauteur' and category=0;
78
name author category email password proxy bitmap msg urlscol urlhttp timeout nbcnx creation livinguntil lang type subcat subtype reg scs capacity userISP CCident
79
patnom patauteur 0 p.favre@cryo-networks.fr NULL NULL #p2sndnq6ae5g1u6t essai salut scol://195.242.78.119:patauteur.patnom NULL NULL NULL 950036174 -882087474 NULL 3 0 3 1 Pub/patnom/futur_divers.scs NULL pat CC1
83
name_id int not null auto_increment,
85
INDEX name_idx (name(5)),
88
INSERT t1 VALUES(NULL,'/');
89
INSERT t1 VALUES(NULL,'[T,U]_axpby');
90
SELECT * FROM t1 WHERE name='[T,U]_axpy';
92
SELECT * FROM t1 WHERE name='[T,U]_axpby';
97
name_id int not null auto_increment,
98
name char(255) binary,
99
INDEX name_idx (name(5)),
100
primary key (name_id)
102
INSERT t2 select * from t1;
103
SELECT * FROM t2 WHERE name='[T,U]_axpy';
105
SELECT * FROM t2 WHERE name='[T,U]_axpby';
108
CREATE TABLE t3 SELECT * FROM t2 WHERE name='[T,U]_axpby';
109
SELECT * FROM t2 WHERE name='[T,U]_axpby';
115
SEQNO numeric(12 ) not null,
116
MOTYPEID numeric(12 ) not null,
117
MOINSTANCEID numeric(12 ) not null,
118
ATTRID numeric(12 ) not null,
119
VALUE varchar(120) not null,
120
primary key (SEQNO, MOTYPEID, MOINSTANCEID, ATTRID, VALUE )
122
INSERT INTO t1 VALUES (1, 1, 1, 1, 'a');
123
INSERT INTO t1 VALUES (1, 1, 1, 1, 'b');
124
INSERT INTO t1 VALUES (1, 1, 1, 1, 'a');
125
ERROR 23000: Duplicate entry '1-1-1-1-a' for key 'PRIMARY'
129
b int NOT NULL default '0',
130
PRIMARY KEY (a(32),b)
132
INSERT INTO t1 VALUES ('a',1),('a',2);
133
SELECT * FROM t1 WHERE a='a' AND b=2;
136
SELECT * FROM t1 WHERE a='a' AND b in (2);
139
SELECT * FROM t1 WHERE a='a' AND b in (1,2);
144
create table t1 (a int not null unique, b int unique, c int, d int not null primary key, key(c), e int not null unique);
146
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
147
t1 0 PRIMARY 1 d A 0 NULL NULL BTREE
148
t1 0 a 1 a A 0 NULL NULL BTREE
149
t1 0 e 1 e A 0 NULL NULL BTREE
150
t1 0 b 1 b A 0 NULL NULL YES BTREE
151
t1 1 c 1 c A 0 NULL NULL YES BTREE
153
CREATE TABLE t1 (c VARCHAR(10) NOT NULL,i INT PRIMARY KEY NOT NULL AUTO_INCREMENT, UNIQUE (c,i));
154
INSERT INTO t1 (c) VALUES (NULL),(NULL);
155
ERROR 23000: Column 'c' cannot be null
158
INSERT INTO t1 (c) VALUES ('a'),('a');
163
DROP TABLE IF EXISTS t1;
164
CREATE TABLE t1 (c CHAR(10) NULL, i INT PRIMARY KEY NOT NULL AUTO_INCREMENT, UNIQUE (c,i));
165
INSERT INTO t1 (c) VALUES (NULL),(NULL);
170
INSERT INTO t1 (c) VALUES ('a'),('a');
178
CREATE TABLE t1 (id int auto_increment, name char(50), primary key (id)) engine=myisam;
179
insert into t1 (name) values ('a'), ('b'),('c'),('d'),('e'),('f'),('g');
180
explain select 1 from t1 where id =2;
181
id select_type table type possible_keys key key_len ref rows Extra
182
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index
183
explain select 1 from t1 where id =2 or id=3;
184
id select_type table type possible_keys key key_len ref rows Extra
185
1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 7 Using where; Using index
186
explain select name from t1 where id =2;
187
id select_type table type possible_keys key key_len ref rows Extra
188
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
189
ALTER TABLE t1 DROP PRIMARY KEY, ADD INDEX (id);
190
explain select 1 from t1 where id =2;
191
id select_type table type possible_keys key key_len ref rows Extra
192
1 SIMPLE t1 ref id id 4 const 1 Using index
194
CREATE TABLE t1 (numeropost int NOT NULL default '0', numreponse int NOT NULL auto_increment, PRIMARY KEY (numeropost,numreponse), UNIQUE KEY numreponse (numreponse));
195
INSERT INTO t1 (numeropost,numreponse) VALUES ('1','1'),('1','2'),('2','3'),('2','4');
196
SELECT numeropost FROM t1 WHERE numreponse='1';
199
EXPLAIN SELECT numeropost FROM t1 WHERE numreponse='1';
200
id select_type table type possible_keys key key_len ref rows Extra
201
1 SIMPLE t1 const numreponse numreponse 4 const 1 Using index
203
SELECT numeropost FROM t1 WHERE numreponse='1';
207
create table t1 (c varchar(30), t text, unique (c(2)), unique (t(3))) engine=myisam;
208
show create table t1;
210
t1 CREATE TABLE `t1` (
213
UNIQUE KEY `c` (`c`()),
214
UNIQUE KEY `t` (`t`())
216
insert t1 values ('cccc', 'tttt'),
217
(0xD0B1212223D0B1D0B1D0B1D0B1D0B1, 0xD0B1D0B1212223D0B1D0B1D0B1D0B1),
218
(0xD0B1222123D0B1D0B1D0B1D0B1D0B1, 0xD0B1D0B1222123D0B1D0B1D0B1D0B1);
219
insert t1 (c) values ('cc22');
220
ERROR 23000: Duplicate entry 'cc' for key 'c'
221
insert t1 (t) values ('ttt22');
222
ERROR 23000: Duplicate entry 'ttt' for key 't'
223
insert t1 (c) values (0xD0B1212322D0B1D0B1D0B1D0B1D0B1);
224
ERROR 23000: Duplicate entry 'б!' for key 'c'
225
insert t1 (t) values (0xD0B1D0B1212322D0B1D0B1D0B1D0B1);
226
ERROR 23000: Duplicate entry 'бб!' for key 't'
227
select c from t1 where c='cccc';
230
select t from t1 where t='tttt';
233
select c from t1 where c=0xD0B1212223D0B1D0B1D0B1D0B1D0B1;
236
select t from t1 where t=0xD0B1D0B1212223D0B1D0B1D0B1D0B1;
240
DROP TABLE IF EXISTS t1;
242
Note 1051 Unknown table 't1'
249
INSERT INTO t1 VALUES (1,'\Z\Z\Z\Z');
250
INSERT INTO t1 VALUES (2,'\Z\Z\Z\Z\Z\Z');
251
INSERT INTO t1 VALUES (3,'\Z\Z\Z\Z');
252
select c1 from t1 where c2='\Z\Z\Z\Z';
256
DELETE FROM t1 WHERE (c1 = 1);
258
Table Op Msg_type Msg_text
259
test.t1 check status OK
260
select c1 from t1 where c2='\Z\Z\Z\Z';
263
DELETE FROM t1 WHERE (c1 = 3);
265
Table Op Msg_type Msg_text
266
test.t1 check status OK
267
select c1 from t1 where c2='\Z\Z\Z\Z';
270
insert into t1 values(1,"aaaa"),(2,"aaab"),(3,"aaac"),(4,"aaccc");
271
delete from t1 where c1=3;
272
delete from t1 where c1=1;
273
delete from t1 where c1=4;
275
Table Op Msg_type Msg_text
276
test.t1 check status OK
278
create table t1 (c char(10), index (c(0)));
279
ERROR HY000: Key part 'c' length cannot be 0
280
create table t1 (c char(10), index (c,c));
281
ERROR 42S21: Duplicate column name 'c'
282
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1));
283
ERROR 42S21: Duplicate column name 'c1'
284
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2));
285
ERROR 42S21: Duplicate column name 'c1'
286
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1));
287
ERROR 42S21: Duplicate column name 'c1'
288
create table t1 (c1 char(10), c2 char(10));
289
alter table t1 add key (c1,c1);
290
ERROR 42S21: Duplicate column name 'c1'
291
alter table t1 add key (c2,c1,c1);
292
ERROR 42S21: Duplicate column name 'c1'
293
alter table t1 add key (c1,c2,c1);
294
ERROR 42S21: Duplicate column name 'c1'
295
alter table t1 add key (c1,c1,c2);
296
ERROR 42S21: Duplicate column name 'c1'
304
Field Type Null Key Default Extra
307
show create table t1;
309
t1 CREATE TABLE `t1` (
312
UNIQUE KEY `i1idx` (`i1`),
313
UNIQUE KEY `i2idx` (`i2`)
318
c2 varchar(20) not null,
322
insert into t1 values (1,'');
323
insert into t1 values (2,' \t\tTest String');
324
insert into t1 values (3,' \n\tTest String');
325
update t1 set c2 = 'New Test String' where c1 = 1;
333
create table t1 (a varchar(10), b varchar(10), key(a(10),b(10)));
334
show create table t1;
336
t1 CREATE TABLE `t1` (
341
alter table t1 modify b varchar(20);
342
show create table t1;
344
t1 CREATE TABLE `t1` (
349
alter table t1 modify a varchar(20);
350
show create table t1;
352
t1 CREATE TABLE `t1` (
358
create table t1 (a int not null primary key, b varchar(20) not null unique);
360
Field Type Null Key Default Extra
362
b varchar(20) NO UNI NULL
364
create table t1 (a int not null primary key, b int not null unique);
366
Field Type Null Key Default Extra
370
create table t1 (a int not null primary key, b varchar(20) not null, unique (b(10)));
372
Field Type Null Key Default Extra
374
b varchar(20) NO UNI NULL
376
create table t1 (a int not null primary key, b varchar(20) not null, c varchar(20) not null, unique(b(10),c(10)));
378
Field Type Null Key Default Extra
380
b varchar(20) NO MUL NULL
381
c varchar(20) NO NULL
393
index i5 (c1, c2, c3, c4),
394
primary key (c2, c3),
396
show create table t1;
398
t1 CREATE TABLE `t1` (
400
`c2` varchar(12) NOT NULL,
401
`c3` varchar(123) NOT NULL,
402
`c4` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
403
PRIMARY KEY (`c2`,`c3`),
404
UNIQUE KEY `i4` (`c4`),
409
KEY `i5` (`c1`,`c2`,`c3`,`c4`),
412
alter table t1 drop index c1;
413
alter table t1 add index (c1);
414
alter table t1 add index (c1);
415
alter table t1 drop index i3;
416
alter table t1 add index i3 (c3);
417
alter table t1 drop index i2, drop index i4;
418
alter table t1 add index i2 (c2), add index i4 (c4);
419
alter table t1 drop index i2, drop index i4, add index i6 (c2, c4);
420
alter table t1 add index i2 (c2), add index i4 (c4), drop index i6;
421
alter table t1 drop index i2, drop index i4, add unique i4 (c4);
422
alter table t1 add index i2 (c2), drop index i4, add index i4 (c4);
423
alter table t1 drop index c2, add index (c2(4),c3(7));
424
alter table t1 drop index c2, add index (c2(4),c3(7));
425
alter table t1 add primary key (c1, c2), drop primary key;
426
alter table t1 drop primary key;
427
alter table t1 add primary key (c1, c2), drop primary key;
428
ERROR 42000: Can't DROP 'PRIMARY'; check that column/key exists
429
show create table t1;
431
t1 CREATE TABLE `t1` (
433
`c2` varchar(12) NOT NULL,
434
`c3` varchar(123) NOT NULL,
435
`c4` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
437
KEY `i5` (`c1`,`c2`,`c3`,`c4`),
443
KEY `c2` (`c2`(),`c3`())
445
insert into t1 values(1, 'a', 'a', NULL);
446
insert into t1 values(1, 'b', 'b', NULL);
447
alter table t1 drop index i3, drop index i2, drop index i1;
448
alter table t1 add index i3 (c3), add index i2 (c2), add unique index i1 (c1);
449
ERROR 23000: Duplicate entry '1' for key 'i1'
451
CREATE TABLE t1( a int, KEY(a) ) ENGINE=MyISAM;
452
INSERT INTO t1 VALUES( 1 );
453
ALTER TABLE t1 DISABLE KEYS;
454
EXPLAIN SELECT MAX(a) FROM t1 FORCE INDEX(a);
455
id select_type table type possible_keys key key_len ref rows Extra
456
1 SIMPLE t1 system NULL NULL NULL NULL 1
459
a INTEGER auto_increment PRIMARY KEY,
465
a INTEGER auto_increment PRIMARY KEY,
476
INDEX (b, d, e, f, g, h, i, j, c),
479
INSERT INTO t2 VALUES
480
(NULL, 1, 254, '1000-01-01 00:00:00', 257, 0, 0, 0, 0, 0),
481
(NULL, 2, 1, '2004-11-30 12:00:00', 1, 0, 0, 0, 0, 0),
482
(NULL, 3, 1, '2004-11-30 12:00:00', 1, 0, 0, 2, -21600, 0),
483
(NULL, 4, 1, '2004-11-30 12:00:00', 1, 0, 0, 2, -10800, 0),
484
(NULL, 5, 1, '2004-11-30 12:00:00', 1, 0, 0, 5, -10800, 0),
485
(NULL, 6, 1, '2004-11-30 12:00:00', 102, 0, 0, 0, 0, 0),
486
(NULL, 7, 1, '2004-11-30 12:00:00', 105, 2, 0, 0, 0, 0),
487
(NULL, 8, 1, '2004-11-30 12:00:00', 105, 10, 0, 0, 0, 0);
488
INSERT INTO t1 (b, c, d) VALUES
489
(3388000, -553000, NULL),
490
(3388000, -553000, NULL);
492
create table t1(a int not null, key aa(a),
493
b char(10) not null, unique key bb(b(1)),
494
c char(4) not null, unique key cc(c));
496
Field Type Null Key Default Extra
498
b varchar(10) NO UNI NULL
499
c varchar(4) NO PRI NULL
500
show create table t1;
502
t1 CREATE TABLE `t1` (
504
`b` varchar(10) NOT NULL,
505
`c` varchar(4) NOT NULL,
506
UNIQUE KEY `cc` (`c`),
507
UNIQUE KEY `bb` (`b`()),
511
create table t1(a int not null, key aa(a),
512
b char(10) not null, unique key bb(b(1)),
515
Field Type Null Key Default Extra
517
b varchar(10) NO UNI NULL
519
alter table t1 add unique key cc(c);
521
Field Type Null Key Default Extra
523
b varchar(10) NO UNI NULL
524
c varchar(4) NO PRI NULL
525
show create table t1;
527
t1 CREATE TABLE `t1` (
529
`b` varchar(10) NOT NULL,
530
`c` varchar(4) NOT NULL,
531
UNIQUE KEY `cc` (`c`),
532
UNIQUE KEY `bb` (`b`()),
537
DROP TABLE IF EXISTS t1;
538
CREATE TABLE t1 (a INT PRIMARY KEY AUTO_INCREMENT);
539
INSERT INTO t1 VALUES (), (), ();
545
GROUP BY GREATEST(LAST_INSERT_ID(), t1.a) ASC
552
CREATE TABLE t1 (a INT, b INT, INDEX (a,b));
553
INSERT INTO t1 (a, b)
555
(1,1), (1,2), (1,3), (1,4), (1,5),
556
(2,2), (2,3), (2,1), (3,1), (4,1), (4,2), (4,3), (4,4), (4,5), (4,6);
557
EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE
558
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
559
id select_type table type possible_keys key key_len ref rows Extra
560
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
561
2 SUBQUERY t1 range NULL a 5 NULL 3 Using index for group-by
562
SELECT 1 as RES FROM t1 AS t1_outer WHERE
563
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;