~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/r/key.result

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
drop table if exists t1,t2,t3;
 
2
SET SQL_WARNINGS=1;
 
3
CREATE TABLE t1 (
 
4
ID CHAR(32) NOT NULL,
 
5
name CHAR(32) NOT NULL,
 
6
value CHAR(255),
 
7
INDEX indexIDname (ID(8),name(8))
 
8
) ;
 
9
INSERT INTO t1 VALUES
 
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');
 
14
INSERT INTO t1 VALUES
 
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';
 
20
value
 
21
personal employee company
 
22
drop table t1;
 
23
CREATE TABLE t1 (
 
24
price int(5) DEFAULT '0' NOT NULL,
 
25
area varchar(40) DEFAULT '' NOT NULL,
 
26
type varchar(40) 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)
 
32
);
 
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 VALUES (900,'Vancouver','Shared/Roomate','','','','');
 
36
Warnings:
 
37
Warning 1265    Data truncated for column 'transityes' at row 1
 
38
Warning 1265    Data truncated for column 'shopsyes' at row 1
 
39
Warning 1265    Data truncated for column 'schoolsyes' at row 1
 
40
Warning 1265    Data truncated for column 'petsyes' at row 1
 
41
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y');
 
42
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y');
 
43
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y');
 
44
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y');
 
45
INSERT INTO t1 VALUES (900,'Vancouver','Shared/Roomate','Y','Y','Y','Y');
 
46
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;
 
47
price   area    type    transityes      shopsyes        schoolsyes      petsyes
 
48
drop table t1;
 
49
CREATE TABLE t1 (program enum('signup','unique','sliding') not null,  type enum('basic','sliding','signup'),  sites set('mt'),  PRIMARY KEY (program));
 
50
ALTER TABLE t1 modify program enum('signup','unique','sliding');
 
51
drop table t1;
 
52
CREATE TABLE t1 (
 
53
name varchar(50) DEFAULT '' NOT NULL,
 
54
author varchar(50) DEFAULT '' NOT NULL,
 
55
category decimal(10,0) DEFAULT '0' NOT NULL,
 
56
email varchar(50),
 
57
password varchar(50),
 
58
proxy varchar(50),
 
59
bitmap varchar(20),
 
60
msg varchar(255),
 
61
urlscol varchar(127),
 
62
urlhttp varchar(127),
 
63
timeout decimal(10,0),
 
64
nbcnx decimal(10,0),
 
65
creation decimal(10,0),
 
66
livinguntil decimal(10,0),
 
67
lang decimal(10,0),
 
68
type decimal(10,0),
 
69
subcat decimal(10,0),
 
70
subtype decimal(10,0),
 
71
reg char(1),
 
72
scs varchar(255),
 
73
capacity decimal(10,0),
 
74
userISP varchar(50),
 
75
CCident varchar(50) DEFAULT '' NOT NULL,
 
76
PRIMARY KEY (name,author,category)
 
77
);
 
78
INSERT INTO t1 VALUES
 
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');
 
80
INSERT INTO t1 VALUES
 
81
('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');
 
82
select * from t1 where name='patnom' and author='patauteur' and category=0;
 
83
name    author  category        email   password        proxy   bitmap  msg     urlscol urlhttp timeout nbcnx   creation        livinguntil     lang    type    subcat  subtype reg     scs     capacity        userISP CCident
 
84
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
 
85
drop table t1;
 
86
create table t1
 
87
(
 
88
name_id int not null auto_increment,
 
89
name blob,
 
90
INDEX name_idx (name(5)),
 
91
primary key (name_id)
 
92
);
 
93
INSERT t1 VALUES(NULL,'/');
 
94
INSERT t1 VALUES(NULL,'[T,U]_axpby');
 
95
SELECT * FROM t1 WHERE name='[T,U]_axpy';
 
96
name_id name
 
97
SELECT * FROM t1 WHERE name='[T,U]_axpby';
 
98
name_id name
 
99
2       [T,U]_axpby
 
100
create table t2
 
101
(
 
102
name_id int not null auto_increment,
 
103
name char(255) binary,
 
104
INDEX name_idx (name(5)),
 
105
primary key (name_id)
 
106
);
 
107
INSERT t2 select * from t1;
 
108
SELECT * FROM t2 WHERE name='[T,U]_axpy';
 
109
name_id name
 
110
SELECT * FROM t2 WHERE name='[T,U]_axpby';
 
111
name_id name
 
112
2       [T,U]_axpby
 
113
CREATE TABLE t3 SELECT * FROM t2 WHERE name='[T,U]_axpby';
 
114
SELECT * FROM t2 WHERE name='[T,U]_axpby';
 
115
name_id name
 
116
2       [T,U]_axpby
 
117
drop table t1,t2,t3;
 
118
create table t1
 
119
(
 
120
SEQNO                         numeric(12 ) not null,
 
121
MOTYPEID                 numeric(12 ) not null,
 
122
MOINSTANCEID     numeric(12 ) not null,
 
123
ATTRID                       numeric(12 ) not null,
 
124
VALUE                         varchar(120) not null,
 
125
primary key (SEQNO, MOTYPEID, MOINSTANCEID, ATTRID, VALUE )
 
126
);
 
127
INSERT INTO t1 VALUES (1, 1, 1, 1, 'a');
 
128
INSERT INTO t1 VALUES (1, 1, 1, 1, 'b');
 
129
INSERT INTO t1 VALUES (1, 1, 1, 1, 'a');
 
130
ERROR 23000: Duplicate entry '1-1-1-1-a' for key 'PRIMARY'
 
131
drop table t1;
 
132
CREATE TABLE t1 (
 
133
a tinytext NOT NULL,
 
134
b tinyint(3) unsigned NOT NULL default '0',
 
135
PRIMARY KEY (a(32),b)
 
136
) ENGINE=MyISAM;
 
137
INSERT INTO t1 VALUES ('a',1),('a',2);
 
138
SELECT * FROM t1 WHERE a='a' AND b=2;
 
139
a       b
 
140
a       2
 
141
SELECT * FROM t1 WHERE a='a' AND b in (2);
 
142
a       b
 
143
a       2
 
144
SELECT * FROM t1 WHERE a='a' AND b in (1,2);
 
145
a       b
 
146
a       1
 
147
a       2
 
148
drop table t1;
 
149
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);
 
150
show keys from t1;
 
151
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
152
t1      0       PRIMARY 1       d       A       0       NULL    NULL            BTREE           
 
153
t1      0       a       1       a       A       0       NULL    NULL            BTREE           
 
154
t1      0       e       1       e       A       0       NULL    NULL            BTREE           
 
155
t1      0       b       1       b       A       NULL    NULL    NULL    YES     BTREE           
 
156
t1      1       c       1       c       A       NULL    NULL    NULL    YES     BTREE           
 
157
drop table t1;
 
158
CREATE TABLE t1 (c CHAR(10) NOT NULL,i INT NOT NULL AUTO_INCREMENT,
 
159
UNIQUE (c,i));
 
160
INSERT INTO t1 (c) VALUES (NULL),(NULL);
 
161
Warnings:
 
162
Warning 1048    Column 'c' cannot be null
 
163
Warning 1048    Column 'c' cannot be null
 
164
SELECT * FROM t1;
 
165
c       i
 
166
        1
 
167
        2
 
168
INSERT INTO t1 (c) VALUES ('a'),('a');
 
169
SELECT * FROM t1;
 
170
c       i
 
171
        1
 
172
        2
 
173
a       1
 
174
a       2
 
175
DROP TABLE IF EXISTS t1;
 
176
CREATE TABLE t1 (c CHAR(10) NULL, i INT NOT NULL AUTO_INCREMENT,
 
177
UNIQUE (c,i));
 
178
INSERT INTO t1 (c) VALUES (NULL),(NULL);
 
179
SELECT * FROM t1;
 
180
c       i
 
181
NULL    1
 
182
NULL    2
 
183
INSERT INTO t1 (c) VALUES ('a'),('a');
 
184
SELECT * FROM t1;
 
185
c       i
 
186
NULL    1
 
187
NULL    2
 
188
a       1
 
189
a       2
 
190
drop table t1;
 
191
create table t1 (i int, a char(200), b text, unique (a), unique (b(300))) charset utf8;
 
192
insert t1 values (1, repeat('a',210), repeat('b', 310));
 
193
Warnings:
 
194
Warning 1265    Data truncated for column 'a' at row 1
 
195
insert t1 values (2, repeat(0xD0B1,215), repeat(0xD0B1, 310));
 
196
Warnings:
 
197
Warning 1265    Data truncated for column 'a' at row 1
 
198
select i, length(a), length(b), char_length(a), char_length(b) from t1;
 
199
i       length(a)       length(b)       char_length(a)  char_length(b)
 
200
1       200     310     200     310
 
201
2       400     620     200     310
 
202
select i from t1 where a=repeat(_utf8 'a',200);
 
203
i
 
204
1
 
205
select i from t1 where a=repeat(_utf8 0xD0B1,200);
 
206
i
 
207
2
 
208
select i from t1 where b=repeat(_utf8 'b',310);
 
209
i
 
210
1
 
211
drop table t1;
 
212
CREATE TABLE t1 (id int unsigned auto_increment, name char(50), primary key (id)) engine=myisam;
 
213
insert into t1 (name) values ('a'), ('b'),('c'),('d'),('e'),('f'),('g');
 
214
explain select 1 from t1 where id =2;
 
215
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
216
1       SIMPLE  t1      const   PRIMARY PRIMARY 4       const   1       Using index
 
217
explain select 1 from t1 where id =2 or id=3;
 
218
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
219
1       SIMPLE  t1      index   PRIMARY PRIMARY 4       NULL    7       Using where; Using index
 
220
explain select name from t1 where id =2;
 
221
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
222
1       SIMPLE  t1      const   PRIMARY PRIMARY 4       const   1       
 
223
ALTER TABLE t1 DROP PRIMARY KEY, ADD INDEX (id);
 
224
explain select 1 from t1 where id =2;
 
225
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
226
1       SIMPLE  t1      ref     id      id      4       const   1       Using index
 
227
drop table t1;
 
228
CREATE TABLE t1 (numeropost mediumint(8) unsigned NOT NULL default '0', numreponse int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (numeropost,numreponse), UNIQUE KEY numreponse (numreponse));
 
229
INSERT INTO t1 (numeropost,numreponse) VALUES ('1','1'),('1','2'),('2','3'),('2','4');
 
230
SELECT numeropost FROM t1 WHERE numreponse='1';
 
231
numeropost
 
232
1
 
233
EXPLAIN SELECT numeropost FROM t1 WHERE numreponse='1';
 
234
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
235
1       SIMPLE  t1      const   numreponse      numreponse      4       const   1       Using index
 
236
FLUSH TABLES;
 
237
SELECT numeropost FROM t1 WHERE numreponse='1';
 
238
numeropost
 
239
1
 
240
drop table t1;
 
241
create table t1 (c varchar(30) character set utf8, t text character set utf8, unique (c(2)), unique (t(3))) engine=myisam;
 
242
show create table t1;
 
243
Table   Create Table
 
244
t1      CREATE TABLE `t1` (
 
245
  `c` varchar(30) CHARACTER SET utf8 DEFAULT NULL,
 
246
  `t` text CHARACTER SET utf8,
 
247
  UNIQUE KEY `c` (`c`(2)),
 
248
  UNIQUE KEY `t` (`t`(3))
 
249
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
250
insert t1 values ('cccc', 'tttt'),
 
251
(0xD0B1212223D0B1D0B1D0B1D0B1D0B1, 0xD0B1D0B1212223D0B1D0B1D0B1D0B1),
 
252
(0xD0B1222123D0B1D0B1D0B1D0B1D0B1, 0xD0B1D0B1222123D0B1D0B1D0B1D0B1);
 
253
insert t1 (c) values ('cc22');
 
254
ERROR 23000: Duplicate entry 'cc' for key 'c'
 
255
insert t1 (t) values ('ttt22');
 
256
ERROR 23000: Duplicate entry 'ttt' for key 't'
 
257
insert t1 (c) values (0xD0B1212322D0B1D0B1D0B1D0B1D0B1);
 
258
ERROR 23000: Duplicate entry 'б!' for key 'c'
 
259
insert t1 (t) values (0xD0B1D0B1212322D0B1D0B1D0B1D0B1);
 
260
ERROR 23000: Duplicate entry 'бб!' for key 't'
 
261
select c from t1 where c='cccc';
 
262
c
 
263
cccc
 
264
select t from t1 where t='tttt';
 
265
t
 
266
tttt
 
267
select c from t1 where c=0xD0B1212223D0B1D0B1D0B1D0B1D0B1;
 
268
c
 
269
?!"#?????
 
270
select t from t1 where t=0xD0B1D0B1212223D0B1D0B1D0B1D0B1;
 
271
t
 
272
??!"#????
 
273
drop table t1;
 
274
DROP TABLE IF EXISTS t1;
 
275
Warnings:
 
276
Note    1051    Unknown table 't1'
 
277
CREATE TABLE t1 (
 
278
c1 int,
 
279
c2 varbinary(240),
 
280
UNIQUE KEY (c1),
 
281
KEY (c2)
 
282
) ENGINE=MyISAM;
 
283
INSERT INTO t1 VALUES (1,'\Z\Z\Z\Z');
 
284
INSERT INTO t1 VALUES (2,'\Z\Z\Z\Z\Z\Z');
 
285
INSERT INTO t1 VALUES (3,'\Z\Z\Z\Z');
 
286
select c1 from t1 where c2='\Z\Z\Z\Z';
 
287
c1
 
288
1
 
289
3
 
290
DELETE FROM t1 WHERE (c1 = 1);
 
291
check table t1;
 
292
Table   Op      Msg_type        Msg_text
 
293
test.t1 check   status  OK
 
294
select c1 from t1 where c2='\Z\Z\Z\Z';
 
295
c1
 
296
3
 
297
DELETE FROM t1 WHERE (c1 = 3);
 
298
check table t1;
 
299
Table   Op      Msg_type        Msg_text
 
300
test.t1 check   status  OK
 
301
select c1 from t1 where c2='\Z\Z\Z\Z';
 
302
c1
 
303
truncate table t1;
 
304
insert into t1 values(1,"aaaa"),(2,"aaab"),(3,"aaac"),(4,"aaccc");
 
305
delete from t1 where c1=3;
 
306
delete from t1 where c1=1;
 
307
delete from t1 where c1=4;
 
308
check table t1;
 
309
Table   Op      Msg_type        Msg_text
 
310
test.t1 check   status  OK
 
311
drop table t1;
 
312
create table t1 (c char(10), index (c(0)));
 
313
ERROR HY000: Key part 'c' length cannot be 0
 
314
create table t1 (c char(10), index (c,c));
 
315
ERROR 42S21: Duplicate column name 'c'
 
316
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1));
 
317
ERROR 42S21: Duplicate column name 'c1'
 
318
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2));
 
319
ERROR 42S21: Duplicate column name 'c1'
 
320
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1));
 
321
ERROR 42S21: Duplicate column name 'c1'
 
322
create table t1 (c1 char(10), c2 char(10));
 
323
alter table t1 add key (c1,c1);
 
324
ERROR 42S21: Duplicate column name 'c1'
 
325
alter table t1 add key (c2,c1,c1);
 
326
ERROR 42S21: Duplicate column name 'c1'
 
327
alter table t1 add key (c1,c2,c1);
 
328
ERROR 42S21: Duplicate column name 'c1'
 
329
alter table t1 add key (c1,c1,c2);
 
330
ERROR 42S21: Duplicate column name 'c1'
 
331
drop table t1;
 
332
create table t1 (
 
333
i1 INT NOT NULL,
 
334
i2 INT NOT NULL,
 
335
UNIQUE i1idx (i1),
 
336
UNIQUE i2idx (i2));
 
337
desc t1;
 
338
Field   Type    Null    Key     Default Extra
 
339
i1      int(11) NO      PRI     NULL    
 
340
i2      int(11) NO      UNI     NULL    
 
341
show create table t1;
 
342
Table   Create Table
 
343
t1      CREATE TABLE `t1` (
 
344
  `i1` int(11) NOT NULL,
 
345
  `i2` int(11) NOT NULL,
 
346
  UNIQUE KEY `i1idx` (`i1`),
 
347
  UNIQUE KEY `i2idx` (`i2`)
 
348
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
349
drop table t1;
 
350
create table t1 (
 
351
c1 int,
 
352
c2 varchar(20) not null,
 
353
primary key (c1),
 
354
key (c2(10))
 
355
) engine=myisam;
 
356
insert into t1 values (1,'');
 
357
insert into t1 values (2,' \t\tTest String');
 
358
insert into t1 values (3,' \n\tTest String');
 
359
update t1 set c2 = 'New Test String' where c1 = 1;
 
360
select * from t1;
 
361
c1      c2
 
362
1       New Test String
 
363
2                       Test String
 
364
3        
 
365
        Test String
 
366
drop table t1;
 
367
create table t1 (a varchar(10), b varchar(10), key(a(10),b(10)));
 
368
show create table t1;
 
369
Table   Create Table
 
370
t1      CREATE TABLE `t1` (
 
371
  `a` varchar(10) DEFAULT NULL,
 
372
  `b` varchar(10) DEFAULT NULL,
 
373
  KEY `a` (`a`,`b`)
 
374
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
375
alter table t1 modify b varchar(20);
 
376
show create table t1;
 
377
Table   Create Table
 
378
t1      CREATE TABLE `t1` (
 
379
  `a` varchar(10) DEFAULT NULL,
 
380
  `b` varchar(20) DEFAULT NULL,
 
381
  KEY `a` (`a`,`b`)
 
382
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
383
alter table t1 modify a varchar(20);
 
384
show create table t1;
 
385
Table   Create Table
 
386
t1      CREATE TABLE `t1` (
 
387
  `a` varchar(20) DEFAULT NULL,
 
388
  `b` varchar(20) DEFAULT NULL,
 
389
  KEY `a` (`a`,`b`)
 
390
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
391
drop table t1;
 
392
create table t1 (a int not null primary key, b varchar(20) not null unique);
 
393
desc t1;
 
394
Field   Type    Null    Key     Default Extra
 
395
a       int(11) NO      PRI     NULL    
 
396
b       varchar(20)     NO      UNI     NULL    
 
397
drop table t1;
 
398
create table t1 (a int not null primary key, b int not null unique);
 
399
desc t1;
 
400
Field   Type    Null    Key     Default Extra
 
401
a       int(11) NO      PRI     NULL    
 
402
b       int(11) NO      UNI     NULL    
 
403
drop table t1;
 
404
create table t1 (a int not null primary key, b varchar(20) not null, unique (b(10)));
 
405
desc t1;
 
406
Field   Type    Null    Key     Default Extra
 
407
a       int(11) NO      PRI     NULL    
 
408
b       varchar(20)     NO      UNI     NULL    
 
409
drop table t1;
 
410
create table t1 (a int not null primary key, b varchar(20) not null, c varchar(20) not null, unique(b(10),c(10)));
 
411
desc t1;
 
412
Field   Type    Null    Key     Default Extra
 
413
a       int(11) NO      PRI     NULL    
 
414
b       varchar(20)     NO      MUL     NULL    
 
415
c       varchar(20)     NO              NULL    
 
416
drop table t1;
 
417
create table t1 (
 
418
c1 int,
 
419
c2 char(12),
 
420
c3 varchar(123),
 
421
c4 timestamp,
 
422
index (c1),
 
423
index i1 (c1),
 
424
index i2 (c2),
 
425
index i3 (c3),
 
426
unique i4 (c4),
 
427
index i5 (c1, c2, c3, c4),
 
428
primary key (c2, c3),
 
429
index (c2, c4));
 
430
show create table t1;
 
431
Table   Create Table
 
432
t1      CREATE TABLE `t1` (
 
433
  `c1` int(11) DEFAULT NULL,
 
434
  `c2` char(12) NOT NULL DEFAULT '',
 
435
  `c3` varchar(123) NOT NULL DEFAULT '',
 
436
  `c4` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 
437
  PRIMARY KEY (`c2`,`c3`),
 
438
  UNIQUE KEY `i4` (`c4`),
 
439
  KEY `c1` (`c1`),
 
440
  KEY `i1` (`c1`),
 
441
  KEY `i2` (`c2`),
 
442
  KEY `i3` (`c3`),
 
443
  KEY `i5` (`c1`,`c2`,`c3`,`c4`),
 
444
  KEY `c2` (`c2`,`c4`)
 
445
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
446
alter table t1 drop index c1;
 
447
alter table t1 add index (c1);
 
448
alter table t1 add index (c1);
 
449
alter table t1 drop index i3;
 
450
alter table t1 add index i3 (c3);
 
451
alter table t1 drop index i2, drop index i4;
 
452
alter table t1 add index i2 (c2), add index i4 (c4);
 
453
alter table t1 drop index i2, drop index i4, add index i6 (c2, c4);
 
454
alter table t1 add index i2 (c2), add index i4 (c4), drop index i6;
 
455
alter table t1 drop index i2, drop index i4, add unique i4 (c4);
 
456
alter table t1 add index i2 (c2), drop index i4, add index i4 (c4);
 
457
alter table t1 drop index c2, add index (c2(4),c3(7));
 
458
alter table t1 drop index c2, add index (c2(4),c3(7));
 
459
alter table t1 add primary key (c1, c2), drop primary key;
 
460
alter table t1 drop primary key;
 
461
alter table t1 add primary key (c1, c2), drop primary key;
 
462
ERROR 42000: Can't DROP 'PRIMARY'; check that column/key exists
 
463
show create table t1;
 
464
Table   Create Table
 
465
t1      CREATE TABLE `t1` (
 
466
  `c1` int(11) NOT NULL DEFAULT '0',
 
467
  `c2` char(12) NOT NULL DEFAULT '',
 
468
  `c3` varchar(123) NOT NULL DEFAULT '',
 
469
  `c4` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 
470
  KEY `i1` (`c1`),
 
471
  KEY `i5` (`c1`,`c2`,`c3`,`c4`),
 
472
  KEY `c1` (`c1`),
 
473
  KEY `c1_2` (`c1`),
 
474
  KEY `i3` (`c3`),
 
475
  KEY `i2` (`c2`),
 
476
  KEY `i4` (`c4`),
 
477
  KEY `c2` (`c2`(4),`c3`(7))
 
478
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
479
insert into t1 values(1, 'a', 'a', NULL);
 
480
insert into t1 values(1, 'b', 'b', NULL);
 
481
alter table t1 drop index i3, drop index i2, drop index i1;
 
482
alter table t1 add index i3 (c3), add index i2 (c2), add unique index i1 (c1);
 
483
ERROR 23000: Duplicate entry '1' for key 'i1'
 
484
drop table t1;
 
485
CREATE TABLE t1( a TINYINT, KEY(a) ) ENGINE=MyISAM;
 
486
INSERT INTO t1 VALUES( 1 );
 
487
ALTER TABLE t1 DISABLE KEYS;
 
488
EXPLAIN SELECT MAX(a) FROM t1 FORCE INDEX(a);
 
489
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
490
1       SIMPLE  t1      system  NULL    NULL    NULL    NULL    1       
 
491
drop table t1;
 
492
CREATE TABLE t1 (
 
493
a INTEGER auto_increment PRIMARY KEY,
 
494
b INTEGER NOT NULL,
 
495
c INTEGER NOT NULL,
 
496
d CHAR(64)
 
497
);
 
498
CREATE TABLE t2 (
 
499
a INTEGER auto_increment PRIMARY KEY,
 
500
b INTEGER NOT NULL,
 
501
c SMALLINT NOT NULL,
 
502
d DATETIME NOT NULL,
 
503
e SMALLINT NOT NULL,
 
504
f INTEGER NOT NULL,
 
505
g INTEGER NOT NULL,  
 
506
h SMALLINT NOT NULL,
 
507
i INTEGER NOT NULL,
 
508
j INTEGER NOT NULL,
 
509
UNIQUE INDEX (b),
 
510
INDEX (b, d, e, f, g, h, i, j, c),
 
511
INDEX (c)
 
512
);
 
513
INSERT INTO t2 VALUES 
 
514
(NULL, 1, 254, '1000-01-01 00:00:00', 257, 0, 0, 0, 0, 0),
 
515
(NULL, 2, 1, '2004-11-30 12:00:00', 1, 0, 0, 0, 0, 0),
 
516
(NULL, 3, 1, '2004-11-30 12:00:00', 1, 0, 0, 2, -21600, 0),
 
517
(NULL, 4, 1, '2004-11-30 12:00:00', 1, 0, 0, 2, -10800, 0),
 
518
(NULL, 5, 1, '2004-11-30 12:00:00', 1, 0, 0, 5, -10800, 0),
 
519
(NULL, 6, 1, '2004-11-30 12:00:00', 102, 0, 0, 0, 0, 0),
 
520
(NULL, 7, 1, '2004-11-30 12:00:00', 105, 2, 0, 0, 0, 0),
 
521
(NULL, 8, 1, '2004-11-30 12:00:00', 105, 10, 0, 0, 0, 0);
 
522
INSERT INTO t1 (b, c, d) VALUES
 
523
(3388000, -553000, NULL),
 
524
(3388000, -553000, NULL);
 
525
DROP TABLE t1, t2;
 
526
create table t1(a int not null, key aa(a), 
 
527
b char(10) not null, unique key bb(b(1)), 
 
528
c char(4) not null, unique key cc(c));
 
529
desc t1;
 
530
Field   Type    Null    Key     Default Extra
 
531
a       int(11) NO      MUL     NULL    
 
532
b       char(10)        NO      UNI     NULL    
 
533
c       char(4) NO      PRI     NULL    
 
534
show create table t1;
 
535
Table   Create Table
 
536
t1      CREATE TABLE `t1` (
 
537
  `a` int(11) NOT NULL,
 
538
  `b` char(10) NOT NULL,
 
539
  `c` char(4) NOT NULL,
 
540
  UNIQUE KEY `cc` (`c`),
 
541
  UNIQUE KEY `bb` (`b`(1)),
 
542
  KEY `aa` (`a`)
 
543
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
544
drop table t1;
 
545
create table t1(a int not null, key aa(a), 
 
546
b char(10) not null, unique key bb(b(1)),
 
547
c char(4) not null);
 
548
desc t1;
 
549
Field   Type    Null    Key     Default Extra
 
550
a       int(11) NO      MUL     NULL    
 
551
b       char(10)        NO      UNI     NULL    
 
552
c       char(4) NO              NULL    
 
553
alter table t1 add unique key cc(c);
 
554
desc t1;
 
555
Field   Type    Null    Key     Default Extra
 
556
a       int(11) NO      MUL     NULL    
 
557
b       char(10)        NO      UNI     NULL    
 
558
c       char(4) NO      PRI     NULL    
 
559
show create table t1;
 
560
Table   Create Table
 
561
t1      CREATE TABLE `t1` (
 
562
  `a` int(11) NOT NULL,
 
563
  `b` char(10) NOT NULL,
 
564
  `c` char(4) NOT NULL,
 
565
  UNIQUE KEY `cc` (`c`),
 
566
  UNIQUE KEY `bb` (`b`(1)),
 
567
  KEY `aa` (`a`)
 
568
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
569
drop table t1;
 
570
End of 5.0 tests
 
571
DROP TABLE IF EXISTS t1;
 
572
CREATE TABLE t1 (a INT PRIMARY KEY AUTO_INCREMENT);
 
573
INSERT INTO t1 VALUES (), (), ();
 
574
SELECT 1 AS c1
 
575
FROM t1
 
576
ORDER BY (
 
577
SELECT 1 AS c2
 
578
FROM t1
 
579
GROUP BY GREATEST(LAST_INSERT_ID(), t1.a) ASC
 
580
LIMIT 1);
 
581
c1
 
582
1
 
583
1
 
584
1
 
585
DROP TABLE t1;
 
586
CREATE TABLE t1 (a INT, b INT, INDEX (a,b));
 
587
INSERT INTO t1 (a, b)
 
588
VALUES
 
589
(1,1), (1,2), (1,3), (1,4), (1,5),
 
590
(2,2), (2,3), (2,1), (3,1), (4,1), (4,2), (4,3), (4,4), (4,5), (4,6);
 
591
EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE 
 
592
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
 
593
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
594
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
 
595
2       SUBQUERY        t1      range   NULL    a       5       NULL    8       Using index for group-by
 
596
SELECT 1 as RES FROM t1 AS t1_outer WHERE 
 
597
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
 
598
RES
 
599
DROP TABLE t1;