69
CREATE TEMPORARY TABLE t1 (
70
id int NOT NULL default '0',
71
category_id int NOT NULL default '0',
72
type_id int NOT NULL default '0',
70
id int(11) unsigned NOT NULL default '0',
71
category_id tinyint(4) unsigned NOT NULL default '0',
72
type_id tinyint(4) unsigned NOT NULL default '0',
73
73
body text NOT NULL,
74
user_id int NOT NULL default '0',
74
user_id int(11) unsigned NOT NULL default '0',
75
75
status enum('new','old') NOT NULL default 'new',
78
78
ALTER TABLE t1 ORDER BY t1.id, t1.status, t1.type_id, t1.user_id, t1.body;
80
create table t1 (i int not null auto_increment primary key);
80
CREATE TABLE t1 (AnamneseId int(10) unsigned NOT NULL auto_increment,B BLOB,PRIMARY KEY (AnamneseId)) engine=myisam;
81
insert into t1 values (null,"hello");
83
ALTER TABLE t1 ADD Column new_col int not null;
86
Table Op Msg_type Msg_text
87
test.t1 optimize status OK
89
create table t1 (i int unsigned not null auto_increment primary key);
81
90
insert into t1 values (null),(null),(null),(null);
82
alter table t1 drop i,add i int not null auto_increment, drop primary key, add primary key (i);
91
alter table t1 drop i,add i int unsigned not null auto_increment, drop primary key, add primary key (i);
114
123
key (n2, n3, n4, n1),
115
124
key (n3, n4, n1, n2),
116
125
key (n4, n1, n2, n3) );
126
alter table t1 disable keys;
118
127
show keys from t1;
119
128
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
120
129
t1 0 n1 1 n1 A 0 NULL NULL BTREE
121
t1 1 n1_2 1 n1 A 0 NULL NULL BTREE
122
t1 1 n1_2 2 n2 A 0 NULL NULL YES BTREE
123
t1 1 n1_2 3 n3 A 0 NULL NULL YES BTREE
124
t1 1 n1_2 4 n4 A 0 NULL NULL YES BTREE
125
t1 1 n2 1 n2 A 0 NULL NULL YES BTREE
126
t1 1 n2 2 n3 A 0 NULL NULL YES BTREE
127
t1 1 n2 3 n4 A 0 NULL NULL YES BTREE
128
t1 1 n2 4 n1 A 0 NULL NULL BTREE
129
t1 1 n3 1 n3 A 0 NULL NULL YES BTREE
130
t1 1 n3 2 n4 A 0 NULL NULL YES BTREE
131
t1 1 n3 3 n1 A 0 NULL NULL BTREE
132
t1 1 n3 4 n2 A 0 NULL NULL YES BTREE
133
t1 1 n4 1 n4 A 0 NULL NULL YES BTREE
134
t1 1 n4 2 n1 A 0 NULL NULL BTREE
135
t1 1 n4 3 n2 A 0 NULL NULL YES BTREE
136
t1 1 n4 4 n3 A 0 NULL NULL YES BTREE
130
t1 1 n1_2 1 n1 A NULL NULL NULL BTREE disabled
131
t1 1 n1_2 2 n2 A NULL NULL NULL YES BTREE disabled
132
t1 1 n1_2 3 n3 A NULL NULL NULL YES BTREE disabled
133
t1 1 n1_2 4 n4 A NULL NULL NULL YES BTREE disabled
134
t1 1 n2 1 n2 A NULL NULL NULL YES BTREE disabled
135
t1 1 n2 2 n3 A NULL NULL NULL YES BTREE disabled
136
t1 1 n2 3 n4 A NULL NULL NULL YES BTREE disabled
137
t1 1 n2 4 n1 A NULL NULL NULL BTREE disabled
138
t1 1 n3 1 n3 A NULL NULL NULL YES BTREE disabled
139
t1 1 n3 2 n4 A NULL NULL NULL YES BTREE disabled
140
t1 1 n3 3 n1 A NULL NULL NULL BTREE disabled
141
t1 1 n3 4 n2 A NULL NULL NULL YES BTREE disabled
142
t1 1 n4 1 n4 A NULL NULL NULL YES BTREE disabled
143
t1 1 n4 2 n1 A NULL NULL NULL BTREE disabled
144
t1 1 n4 3 n2 A NULL NULL NULL YES BTREE disabled
145
t1 1 n4 4 n3 A NULL NULL NULL YES BTREE disabled
139
146
insert into t1 values(10,RAND()*1000,RAND()*1000,RAND());
140
147
insert into t1 values(9,RAND()*1000,RAND()*1000,RAND());
141
148
insert into t1 values(8,RAND()*1000,RAND()*1000,RAND());
146
153
insert into t1 values(3,RAND()*1000,RAND()*1000,RAND());
147
154
insert into t1 values(2,RAND()*1000,RAND()*1000,RAND());
148
155
insert into t1 values(1,RAND()*1000,RAND()*1000,RAND());
151
156
alter table t1 enable keys;
153
Note 1031 Table storage engine for 't1' doesn't have this option
154
157
show keys from t1;
155
158
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
156
t1 0 n1 1 n1 A 2 NULL NULL BTREE
157
t1 1 n1_2 1 n1 A 2 NULL NULL BTREE
158
t1 1 n1_2 2 n2 A 2 NULL NULL YES BTREE
159
t1 1 n1_2 3 n3 A 2 NULL NULL YES BTREE
160
t1 1 n1_2 4 n4 A 2 NULL NULL YES BTREE
161
t1 1 n2 1 n2 A 2 NULL NULL YES BTREE
162
t1 1 n2 2 n3 A 2 NULL NULL YES BTREE
163
t1 1 n2 3 n4 A 2 NULL NULL YES BTREE
164
t1 1 n2 4 n1 A 2 NULL NULL BTREE
165
t1 1 n3 1 n3 A 2 NULL NULL YES BTREE
166
t1 1 n3 2 n4 A 2 NULL NULL YES BTREE
167
t1 1 n3 3 n1 A 2 NULL NULL BTREE
168
t1 1 n3 4 n2 A 2 NULL NULL YES BTREE
169
t1 1 n4 1 n4 A 2 NULL NULL YES BTREE
170
t1 1 n4 2 n1 A 2 NULL NULL BTREE
171
t1 1 n4 3 n2 A 2 NULL NULL YES BTREE
172
t1 1 n4 4 n3 A 2 NULL NULL YES BTREE
159
t1 0 n1 1 n1 A 10 NULL NULL BTREE
160
t1 1 n1_2 1 n1 A 10 NULL NULL BTREE
161
t1 1 n1_2 2 n2 A 10 NULL NULL YES BTREE
162
t1 1 n1_2 3 n3 A 10 NULL NULL YES BTREE
163
t1 1 n1_2 4 n4 A 10 NULL NULL YES BTREE
164
t1 1 n2 1 n2 A 10 NULL NULL YES BTREE
165
t1 1 n2 2 n3 A 10 NULL NULL YES BTREE
166
t1 1 n2 3 n4 A 10 NULL NULL YES BTREE
167
t1 1 n2 4 n1 A 10 NULL NULL BTREE
168
t1 1 n3 1 n3 A 10 NULL NULL YES BTREE
169
t1 1 n3 2 n4 A 10 NULL NULL YES BTREE
170
t1 1 n3 3 n1 A 10 NULL NULL BTREE
171
t1 1 n3 4 n2 A 10 NULL NULL YES BTREE
172
t1 1 n4 1 n4 A 10 NULL NULL YES BTREE
173
t1 1 n4 2 n1 A 10 NULL NULL BTREE
174
t1 1 n4 3 n2 A 10 NULL NULL YES BTREE
175
t1 1 n4 4 n3 A 10 NULL NULL YES BTREE
174
create table t1 (i int not null auto_increment primary key);
177
create table t1 (i int unsigned not null auto_increment primary key);
175
178
alter table t1 rename t2;
176
179
alter table t2 rename t1, add c char(10) comment "no comment";
177
180
show columns from t1;
178
181
Field Type Null Key Default Extra
179
i int NO PRI NULL auto_increment
180
c varchar(10) YES NULL
182
i int(10) unsigned NO PRI NULL auto_increment
182
185
create table t1 (a int, b int);
185
186
insert into t1 values(1,100), (2,100), (3, 100);
186
187
insert into t1 values(1,99), (2,99), (3, 99);
187
188
insert into t1 values(1,98), (2,98), (3, 98);
282
283
insert into t1 values(1,3), (2,3), (3, 3);
283
284
insert into t1 values(1,2), (2,2), (3, 2);
284
285
insert into t1 values(1,1), (2,1), (3, 1);
287
286
alter table t1 add unique (a,b), add key (b);
288
287
show keys from t1;
289
288
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
290
t1 0 a 1 a A 6 NULL NULL YES BTREE
291
t1 0 a 2 b A 300 NULL NULL YES BTREE
292
t1 1 b 1 b A 300 NULL NULL YES BTREE
289
t1 0 a 1 a A NULL NULL NULL YES BTREE
290
t1 0 a 2 b A NULL NULL NULL YES BTREE
291
t1 1 b 1 b A 100 NULL NULL YES BTREE
293
292
analyze table t1;
294
293
Table Op Msg_type Msg_text
295
294
test.t1 analyze status OK
296
295
show keys from t1;
297
296
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
298
t1 0 a 1 a A 6 NULL NULL YES BTREE
297
t1 0 a 1 a A 3 NULL NULL YES BTREE
299
298
t1 0 a 2 b A 300 NULL NULL YES BTREE
300
t1 1 b 1 b A 300 NULL NULL YES BTREE
302
CREATE TEMPORARY TABLE t1 (
303
Host varchar(16) NOT NULL default '',
304
User varchar(16) NOT NULL default '',
299
t1 1 b 1 b A 100 NULL NULL YES BTREE
301
CREATE TABLE t1 (i int(10), index(i) );
302
ALTER TABLE t1 DISABLE KEYS;
303
INSERT DELAYED INTO t1 VALUES(1),(2),(3);
304
ALTER TABLE t1 ENABLE KEYS;
307
Host varchar(16) binary NOT NULL default '',
308
User varchar(16) binary NOT NULL default '',
309
PRIMARY KEY (Host,User)
311
ALTER TABLE t1 DISABLE KEYS;
312
LOCK TABLES t1 WRITE;
313
INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty');
315
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
316
t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE
317
t1 0 PRIMARY 2 User A 0 NULL NULL BTREE
318
ALTER TABLE t1 ENABLE KEYS;
321
Table Op Msg_type Msg_text
322
test.t1 check status OK
325
Host varchar(16) binary NOT NULL default '',
326
User varchar(16) binary NOT NULL default '',
305
327
PRIMARY KEY (Host,User),
341
381
drop table if exists t1;
343
383
Note 1051 Unknown table 't1'
344
create TEMPORARY table t1 ( a varchar(10) not null primary key ) engine=myisam;
384
create table t1 ( a varchar(10) not null primary key ) engine=myisam;
346
386
alter table t1 modify a varchar(10);
348
388
alter table t1 modify a varchar(10) not null;
349
389
drop table if exists t1;
350
create TEMPORARY table t1 (a int, b int, c int, d int, e int, f int, g int, h int,i int, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM;
351
insert into t1 (a,b,c,d,e,f,g,h,i) values(1,1,1,1,1,1,1,1,1);
390
create table t1 (a int, b int, c int, d int, e int, f int, g int, h int,i int, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM;
391
insert into t1 (a) values(1);
352
392
show table status like 't1';
353
393
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
394
t1 MyISAM 10 Fixed 1 37 X X X X X X X X latin1_swedish_ci NULL
354
395
alter table t1 modify a int;
355
396
show table status like 't1';
356
397
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
398
t1 MyISAM 10 Fixed 1 37 X X X X X X X X latin1_swedish_ci NULL
358
create TEMPORARY table t1 (a int not null default 0, b int not null default 0, c int not null default 0, d int not null default 0, e int not null default 0, f int not null default 0, g int not null default 0, h int not null default 0,i int not null default 0, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM;
400
create table t1 (a int not null, b int not null, c int not null, d int not null, e int not null, f int not null, g int not null, h int not null,i int not null, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM;
359
401
insert into t1 (a) values(1);
403
Warning 1364 Field 'b' doesn't have a default value
404
Warning 1364 Field 'c' doesn't have a default value
405
Warning 1364 Field 'd' doesn't have a default value
406
Warning 1364 Field 'e' doesn't have a default value
407
Warning 1364 Field 'f' doesn't have a default value
408
Warning 1364 Field 'g' doesn't have a default value
409
Warning 1364 Field 'h' doesn't have a default value
410
Warning 1364 Field 'i' doesn't have a default value
360
411
show table status like 't1';
361
412
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
413
t1 MyISAM 10 Fixed 1 37 X X X X X X X X latin1_swedish_ci NULL
416
create table t1 (a char(10) character set koi8r);
417
insert into t1 values ('����');
418
select a,hex(a) from t1;
421
alter table t1 change a a char(10) character set cp1251;
422
select a,hex(a) from t1;
425
alter table t1 change a a binary(4);
426
select a,hex(a) from t1;
429
alter table t1 change a a char(10) character set cp1251;
430
select a,hex(a) from t1;
433
alter table t1 change a a char(10) character set koi8r;
434
select a,hex(a) from t1;
437
alter table t1 change a a varchar(10) character set cp1251;
438
select a,hex(a) from t1;
441
alter table t1 change a a char(10) character set koi8r;
442
select a,hex(a) from t1;
445
alter table t1 change a a text character set cp1251;
446
select a,hex(a) from t1;
449
alter table t1 change a a char(10) character set koi8r;
450
select a,hex(a) from t1;
454
show create table t1;
456
t1 CREATE TABLE `t1` (
457
`a` char(10) CHARACTER SET koi8r DEFAULT NULL
458
) ENGINE=MyISAM DEFAULT CHARSET=latin1
459
alter table t1 DEFAULT CHARACTER SET latin1;
460
show create table t1;
462
t1 CREATE TABLE `t1` (
463
`a` char(10) CHARACTER SET koi8r DEFAULT NULL
464
) ENGINE=MyISAM DEFAULT CHARSET=latin1
465
alter table t1 CONVERT TO CHARACTER SET latin1;
466
show create table t1;
468
t1 CREATE TABLE `t1` (
469
`a` char(10) DEFAULT NULL
470
) ENGINE=MyISAM DEFAULT CHARSET=latin1
471
alter table t1 DEFAULT CHARACTER SET cp1251;
472
show create table t1;
474
t1 CREATE TABLE `t1` (
475
`a` char(10) CHARACTER SET latin1 DEFAULT NULL
476
) ENGINE=MyISAM DEFAULT CHARSET=cp1251
478
create table t1 (myblob longblob,mytext longtext)
479
default charset latin1 collate latin1_general_cs;
480
show create table t1;
482
t1 CREATE TABLE `t1` (
484
`mytext` longtext COLLATE latin1_general_cs
485
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs
486
alter table t1 character set latin2;
487
show create table t1;
489
t1 CREATE TABLE `t1` (
491
`mytext` longtext CHARACTER SET latin1 COLLATE latin1_general_cs
492
) ENGINE=MyISAM DEFAULT CHARSET=latin2
363
494
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE);
364
495
ALTER TABLE t1 DROP PRIMARY KEY;
365
496
SHOW CREATE TABLE t1;
366
497
Table Create Table
367
498
t1 CREATE TABLE `t1` (
369
`b` int DEFAULT NULL,
499
`a` int(11) NOT NULL,
500
`b` int(11) DEFAULT NULL,
370
501
UNIQUE KEY `b` (`b`)
502
) ENGINE=MyISAM DEFAULT CHARSET=latin1
372
503
ALTER TABLE t1 DROP PRIMARY KEY;
373
504
ERROR 42000: Can't DROP 'PRIMARY'; check that column/key exists
390
531
create table t1 (a int, key(a));
391
532
show indexes from t1;
392
533
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
393
t1 1 a 1 a A 0 NULL NULL YES BTREE
534
t1 1 a 1 a A NULL NULL NULL YES BTREE
394
535
"this used not to disable the index"
395
alter table t1 modify a int;
396
show indexes from t1;
397
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
398
t1 1 a 1 a A 0 NULL NULL YES BTREE
399
alter table t1 enable keys;
401
Note 1031 Table storage engine for 't1' doesn't have this option
402
show indexes from t1;
403
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
404
t1 1 a 1 a A 0 NULL NULL YES BTREE
405
alter table t1 modify a bigint;
406
show indexes from t1;
407
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
408
t1 1 a 1 a A 0 NULL NULL YES BTREE
409
alter table t1 enable keys;
411
Note 1031 Table storage engine for 't1' doesn't have this option
412
show indexes from t1;
413
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
414
t1 1 a 1 a A 0 NULL NULL YES BTREE
415
alter table t1 add b char(10);
416
show indexes from t1;
417
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
418
t1 1 a 1 a A 0 NULL NULL YES BTREE
419
alter table t1 add c decimal(10,2);
420
show indexes from t1;
421
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
422
t1 1 a 1 a A 0 NULL NULL YES BTREE
536
alter table t1 modify a int, disable keys;
537
show indexes from t1;
538
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
539
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled
540
alter table t1 enable keys;
541
show indexes from t1;
542
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
543
t1 1 a 1 a A NULL NULL NULL YES BTREE
544
alter table t1 modify a bigint, disable keys;
545
show indexes from t1;
546
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
547
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled
548
alter table t1 enable keys;
549
show indexes from t1;
550
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
551
t1 1 a 1 a A NULL NULL NULL YES BTREE
552
alter table t1 add b char(10), disable keys;
553
show indexes from t1;
554
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
555
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled
556
alter table t1 add c decimal(10,2), enable keys;
557
show indexes from t1;
558
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
559
t1 1 a 1 a A NULL NULL NULL YES BTREE
423
560
"this however did"
561
alter table t1 disable keys;
425
562
show indexes from t1;
426
563
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
427
t1 1 a 1 a A 0 NULL NULL YES BTREE
564
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled
429
566
Field Type Null Key Default Extra
430
a bigint YES MUL NULL
431
b varchar(10) YES NULL
567
a bigint(20) YES MUL NULL
432
569
c decimal(10,2) YES NULL
433
570
alter table t1 add d decimal(15,5);
434
571
"The key should still be disabled"
435
572
show indexes from t1;
436
573
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
437
t1 1 a 1 a A 0 NULL NULL YES BTREE
574
t1 1 a 1 a A NULL NULL NULL YES BTREE disabled
439
576
"Now will test with one unique index"
440
577
create table t1(a int, b char(10), unique(a));
441
578
show indexes from t1;
442
579
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
443
t1 0 a 1 a A 0 NULL NULL YES BTREE
580
t1 0 a 1 a A NULL NULL NULL YES BTREE
581
alter table t1 disable keys;
445
582
show indexes from t1;
446
583
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
447
t1 0 a 1 a A 0 NULL NULL YES BTREE
584
t1 0 a 1 a A NULL NULL NULL YES BTREE
448
585
alter table t1 enable keys;
450
Note 1031 Table storage engine for 't1' doesn't have this option
451
586
"If no copy on noop change, this won't touch the data file"
452
587
"Unique index, no change"
453
alter table t1 modify a int;
588
alter table t1 modify a int, disable keys;
454
589
show indexes from t1;
455
590
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
456
t1 0 a 1 a A 0 NULL NULL YES BTREE
591
t1 0 a 1 a A NULL NULL NULL YES BTREE
457
592
"Change the type implying data copy"
458
593
"Unique index, no change"
459
alter table t1 modify a bigint;
460
show indexes from t1;
461
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
462
t1 0 a 1 a A 0 NULL NULL YES BTREE
463
alter table t1 modify a bigint;
464
show indexes from t1;
465
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
466
t1 0 a 1 a A 0 NULL NULL YES BTREE
594
alter table t1 modify a bigint, disable keys;
595
show indexes from t1;
596
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
597
t1 0 a 1 a A NULL NULL NULL YES BTREE
598
alter table t1 modify a bigint;
599
show indexes from t1;
600
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
601
t1 0 a 1 a A NULL NULL NULL YES BTREE
467
602
alter table t1 modify a int;
468
603
show indexes from t1;
469
604
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
470
t1 0 a 1 a A 0 NULL NULL YES BTREE
605
t1 0 a 1 a A NULL NULL NULL YES BTREE
472
607
"Now will test with one unique and one non-unique index"
473
608
create table t1(a int, b char(10), unique(a), key(b));
474
609
show indexes from t1;
475
610
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
476
t1 0 a 1 a A 0 NULL NULL YES BTREE
477
t1 1 b 1 b A 0 NULL NULL YES BTREE
611
t1 0 a 1 a A NULL NULL NULL YES BTREE
612
t1 1 b 1 b A NULL NULL NULL YES BTREE
613
alter table t1 disable keys;
479
614
show indexes from t1;
480
615
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
481
t1 0 a 1 a A 0 NULL NULL YES BTREE
482
t1 1 b 1 b A 0 NULL NULL YES BTREE
616
t1 0 a 1 a A NULL NULL NULL YES BTREE
617
t1 1 b 1 b A NULL NULL NULL YES BTREE disabled
483
618
alter table t1 enable keys;
485
Note 1031 Table storage engine for 't1' doesn't have this option
486
619
"If no copy on noop change, this won't touch the data file"
487
620
"The non-unique index will be disabled"
488
alter table t1 modify a int;
621
alter table t1 modify a int, disable keys;
489
622
show indexes from t1;
490
623
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
491
t1 0 a 1 a A 0 NULL NULL YES BTREE
492
t1 1 b 1 b A 0 NULL NULL YES BTREE
624
t1 0 a 1 a A NULL NULL NULL YES BTREE
625
t1 1 b 1 b A NULL NULL NULL YES BTREE disabled
493
626
alter table t1 enable keys;
495
Note 1031 Table storage engine for 't1' doesn't have this option
496
627
show indexes from t1;
497
628
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
498
t1 0 a 1 a A 0 NULL NULL YES BTREE
499
t1 1 b 1 b A 0 NULL NULL YES BTREE
629
t1 0 a 1 a A NULL NULL NULL YES BTREE
630
t1 1 b 1 b A NULL NULL NULL YES BTREE
500
631
"Change the type implying data copy"
501
632
"The non-unique index will be disabled"
502
alter table t1 modify a bigint;
633
alter table t1 modify a bigint, disable keys;
503
634
show indexes from t1;
504
635
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
505
t1 0 a 1 a A 0 NULL NULL YES BTREE
506
t1 1 b 1 b A 0 NULL NULL YES BTREE
636
t1 0 a 1 a A NULL NULL NULL YES BTREE
637
t1 1 b 1 b A NULL NULL NULL YES BTREE disabled
507
638
"Change again the type, but leave the indexes as_is"
508
639
alter table t1 modify a int;
509
640
show indexes from t1;
510
641
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
511
t1 0 a 1 a A 0 NULL NULL YES BTREE
512
t1 1 b 1 b A 0 NULL NULL YES BTREE
642
t1 0 a 1 a A NULL NULL NULL YES BTREE
643
t1 1 b 1 b A NULL NULL NULL YES BTREE disabled
513
644
"Try the same. When data is no copied on similar tables, this is noop"
514
645
alter table t1 modify a int;
515
646
show indexes from t1;
516
647
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
517
t1 0 a 1 a A 0 NULL NULL YES BTREE
518
t1 1 b 1 b A 0 NULL NULL YES BTREE
648
t1 0 a 1 a A NULL NULL NULL YES BTREE
649
t1 1 b 1 b A NULL NULL NULL YES BTREE disabled
520
651
create database mysqltest;
521
652
create table t1 (c1 int);
747
897
alter table t1 change i i bigint;
748
898
select * from t1;
754
904
alter table t1 add unique key (i, v);
755
905
select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
759
create TEMPORARY table t1 (t varchar(255) default null, key t (t(80))) engine=myisam;
909
create table t1 (t varchar(255) default null, key t (t(80)))
910
engine=myisam default charset=latin1;
760
911
alter table t1 change t t text;
762
CREATE TABLE t1 (s CHAR(8));
763
INSERT INTO t1 VALUES ('test');
764
SELECT LENGTH(s) FROM t1;
767
ALTER TABLE t1 MODIFY s CHAR(10);
768
SELECT LENGTH(s) FROM t1;
772
CREATE TABLE t1 (s varbinary(8));
773
INSERT INTO t1 VALUES ('test');
774
SELECT LENGTH(s) FROM t1;
777
SELECT HEX(s) FROM t1;
780
ALTER TABLE t1 MODIFY s varbinary(10);
781
SELECT HEX(s) FROM t1;
784
SELECT LENGTH(s) FROM t1;
913
CREATE TABLE t1 (a varchar(500));
914
ALTER TABLE t1 ADD b GEOMETRY NOT NULL, ADD SPATIAL INDEX(b);
915
SHOW CREATE TABLE t1;
917
t1 CREATE TABLE `t1` (
918
`a` varchar(500) DEFAULT NULL,
919
`b` geometry NOT NULL,
920
SPATIAL KEY `b` (`b`)
921
) ENGINE=MyISAM DEFAULT CHARSET=latin1
922
ALTER TABLE t1 ADD KEY(b(50));
923
SHOW CREATE TABLE t1;
925
t1 CREATE TABLE `t1` (
926
`a` varchar(500) DEFAULT NULL,
927
`b` geometry NOT NULL,
928
SPATIAL KEY `b` (`b`),
930
) ENGINE=MyISAM DEFAULT CHARSET=latin1
931
ALTER TABLE t1 ADD c POINT;
932
SHOW CREATE TABLE t1;
934
t1 CREATE TABLE `t1` (
935
`a` varchar(500) DEFAULT NULL,
936
`b` geometry NOT NULL,
937
`c` point DEFAULT NULL,
938
SPATIAL KEY `b` (`b`),
940
) ENGINE=MyISAM DEFAULT CHARSET=latin1
941
CREATE TABLE t2 (a INT, KEY (a(20)));
942
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
943
ALTER TABLE t1 ADD d INT;
944
ALTER TABLE t1 ADD KEY (d(20));
945
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
946
ALTER TABLE t1 ADD e GEOMETRY NOT NULL, ADD SPATIAL KEY (e(30));
947
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
949
CREATE TABLE t1 (s CHAR(8) BINARY);
950
INSERT INTO t1 VALUES ('test');
951
SELECT LENGTH(s) FROM t1;
954
ALTER TABLE t1 MODIFY s CHAR(10) BINARY;
955
SELECT LENGTH(s) FROM t1;
959
CREATE TABLE t1 (s BINARY(8));
960
INSERT INTO t1 VALUES ('test');
961
SELECT LENGTH(s) FROM t1;
964
SELECT HEX(s) FROM t1;
967
ALTER TABLE t1 MODIFY s BINARY(10);
968
SELECT HEX(s) FROM t1;
971
SELECT LENGTH(s) FROM t1;
788
975
CREATE TABLE t1 (v VARCHAR(3), b INT);
789
976
INSERT INTO t1 VALUES ('abc', 5);
832
1094
SHOW CREATE TABLE `#sql2`;
833
1095
Table Create Table
834
1096
#sql2 CREATE TEMPORARY TABLE `#sql2` (
835
`c1` int DEFAULT NULL
1097
`c1` int(11) DEFAULT NULL
1098
) ENGINE=MyISAM DEFAULT CHARSET=latin1
837
1099
SHOW CREATE TABLE `@0023sql1`;
838
1100
Table Create Table
839
1101
@0023sql1 CREATE TEMPORARY TABLE `@0023sql1` (
840
`c1` int DEFAULT NULL
1102
`c1` int(11) DEFAULT NULL
1103
) ENGINE=MyISAM DEFAULT CHARSET=latin1
842
1104
DROP TABLE `#sql2`, `@0023sql1`;
843
1105
DROP TABLE IF EXISTS t1;
844
1106
DROP TABLE IF EXISTS t2;
845
1107
CREATE TABLE t1 (
846
int_field INTEGER NOT NULL,
1108
int_field INTEGER UNSIGNED NOT NULL,
847
1109
char_field CHAR(10),
848
1110
INDEX(`int_field`)
851
1113
Field Type Null Key Default Extra
852
int_field int NO MUL NULL
853
char_field varchar(10) YES NULL
1114
int_field int(10) unsigned NO MUL NULL
1115
char_field char(10) YES NULL
854
1116
SHOW INDEXES FROM t1;
855
1117
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
856
t1 1 int_field 1 int_field A 0 NULL NULL BTREE
1118
t1 1 int_field 1 int_field A NULL NULL NULL BTREE
857
1119
INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet");
858
1120
"Non-copy data change - new frm, but old data and index files"
859
ALTER TABLE t1 CHANGE int_field unsigned_int_field INTEGER NOT NULL, RENAME t2;
1122
CHANGE int_field unsigned_int_field INTEGER UNSIGNED NOT NULL,
860
1124
SELECT * FROM t1 ORDER BY int_field;
861
1125
ERROR 42S02: Table 'test.t1' doesn't exist
862
1126
SELECT * FROM t2 ORDER BY unsigned_int_field;