5
drop table if exists t1,t2;
6
drop database if exists mysqltest;
10
col1 int not null auto_increment primary key,
11
col2 varchar(30) not null,
12
col3 varchar (20) not null,
13
col4 varchar(4) not null,
14
col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null,
15
col6 int not null, to_be_deleted int);
16
insert into t1 values (2,4,3,5,"PENDING",1,7);
18
add column col4_5 varchar(20) not null after col4,
19
add column col7 varchar(30) not null after col5,
20
add column col8 datetime not null, drop column to_be_deleted,
21
change column col2 fourth varchar(30) not null after col3,
22
modify column col6 int not null first;
26
create table t1 (bandID MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, payoutID SMALLINT UNSIGNED NOT NULL);
27
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
28
alter table t1 add column new_col int, order by payoutid,bandid;
30
alter table t1 order by bandid,payoutid;
34
# Check that pack_keys and dynamic length rows are not forced.
37
GROUP_ID int(10) unsigned DEFAULT '0' NOT NULL,
38
LANG_ID smallint(5) unsigned DEFAULT '0' NOT NULL,
39
NAME varchar(80) DEFAULT '' NOT NULL,
40
PRIMARY KEY (GROUP_ID,LANG_ID),
42
#show table status like "t1";
43
ALTER TABLE t1 CHANGE NAME NAME CHAR(80) not null;
45
SHOW FULL COLUMNS FROM t1;
49
# Test of ALTER TABLE ... ORDER BY
52
create table t1 (n int);
53
insert into t1 values(9),(3),(12),(10);
54
alter table t1 order by n;
59
id int(11) unsigned NOT NULL default '0',
60
category_id tinyint(4) unsigned NOT NULL default '0',
61
type_id tinyint(4) unsigned NOT NULL default '0',
63
user_id int(11) unsigned NOT NULL default '0',
64
status enum('new','old') NOT NULL default 'new',
68
ALTER TABLE t1 ORDER BY t1.id, t1.status, t1.type_id, t1.user_id, t1.body;
72
# The following combination found a hang-bug in MyISAM
75
CREATE TABLE t1 (AnamneseId int(10) unsigned NOT NULL auto_increment,B BLOB,PRIMARY KEY (AnamneseId)) engine=myisam;
76
insert into t1 values (null,"hello");
78
ALTER TABLE t1 ADD Column new_col int not null;
84
# Drop and add an auto_increment column
87
create table t1 (i int unsigned not null auto_increment primary key);
88
insert into t1 values (null),(null),(null),(null);
89
alter table t1 drop i,add i int unsigned not null auto_increment, drop primary key, add primary key (i);
94
# Bug #2628: 'alter table t1 rename mysqltest.t1' silently drops mysqltest.t1
97
create table t1 (name char(15));
98
insert into t1 (name) values ("current");
99
create database mysqltest;
100
create table mysqltest.t1 (name char(15));
101
insert into mysqltest.t1 (name) values ("mysqltest");
103
select * from mysqltest.t1;
104
--error ER_TABLE_EXISTS_ERROR
105
alter table t1 rename mysqltest.t1;
107
select * from mysqltest.t1;
109
drop database mysqltest;
112
# ALTER TABLE ... ENABLE/DISABLE KEYS
114
create table t1 (n1 int not null, n2 int, n3 int, n4 float,
116
key (n1, n2, n3, n4),
117
key (n2, n3, n4, n1),
118
key (n3, n4, n1, n2),
119
key (n4, n1, n2, n3) );
120
alter table t1 disable keys;
126
eval insert into t1 values($1,RAND()*1000,RAND()*1000,RAND());
129
alter table t1 enable keys;
134
# Alter table and rename
137
create table t1 (i int unsigned not null auto_increment primary key);
138
alter table t1 rename t2;
139
alter table t2 rename t1, add c char(10) comment "no comment";
140
show columns from t1;
145
create table t1 (a int, b int);
149
eval insert into t1 values(1,$1), (2,$1), (3, $1);
152
alter table t1 add unique (a,b), add key (b);
159
# Test of ALTER TABLE DELAYED
162
CREATE TABLE t1 (i int(10), index(i) );
163
ALTER TABLE t1 DISABLE KEYS;
164
INSERT DELAYED INTO t1 VALUES(1),(2),(3);
165
ALTER TABLE t1 ENABLE KEYS;
169
# Test ALTER TABLE ENABLE/DISABLE keys when things are locked
173
Host varchar(16) binary NOT NULL default '',
174
User varchar(16) binary NOT NULL default '',
175
PRIMARY KEY (Host,User)
178
ALTER TABLE t1 DISABLE KEYS;
179
LOCK TABLES t1 WRITE;
180
INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty');
182
ALTER TABLE t1 ENABLE KEYS;
192
Host varchar(16) binary NOT NULL default '',
193
User varchar(16) binary NOT NULL default '',
194
PRIMARY KEY (Host,User),
198
ALTER TABLE t1 DISABLE KEYS;
200
LOCK TABLES t1 WRITE;
201
INSERT INTO t1 VALUES ('localhost','root'),('localhost','');
203
ALTER TABLE t1 ENABLE KEYS;
208
# Test RENAME with LOCK TABLES
209
LOCK TABLES t1 WRITE;
210
ALTER TABLE t1 RENAME t2;
216
# Test disable keys with locking
219
Host varchar(16) binary NOT NULL default '',
220
User varchar(16) binary NOT NULL default '',
221
PRIMARY KEY (Host,User),
225
LOCK TABLES t1 WRITE;
226
ALTER TABLE t1 DISABLE KEYS;
231
# BUG#4717 - check for valid table names
233
create table t1 (a int);
234
--error ER_WRONG_TABLE_NAME
235
alter table t1 rename to ``;
236
--error ER_WRONG_TABLE_NAME
237
rename table t1 to ``;
241
# BUG#6236 - ALTER TABLE MODIFY should set implicit NOT NULL on PK columns
243
drop table if exists t1, t2;
244
create table t1 ( a varchar(10) not null primary key ) engine=myisam;
245
create table t2 ( a varchar(10) not null primary key ) engine=merge union=(t1);
247
alter table t1 modify a varchar(10);
248
show create table t2;
250
alter table t1 modify a varchar(10) not null;
251
show create table t2;
252
drop table if exists t1, t2;
254
# The following is also part of bug #6236 (CREATE TABLE didn't properly count
255
# not null columns for primary keys)
257
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;
258
insert into t1 (a) values(1);
259
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
260
show table status like 't1';
261
alter table t1 modify a int;
262
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
263
show table status like 't1';
265
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;
266
insert into t1 (a) values(1);
267
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
268
show table status like 't1';
272
# Test that data get converted when character set is changed
273
# Test that data doesn't get converted when src or dst is BINARY/BLOB
276
create table t1 (a char(10) character set koi8r);
277
insert into t1 values ('ļæ½ļæ½ļæ½ļæ½');
278
select a,hex(a) from t1;
279
alter table t1 change a a char(10) character set cp1251;
280
select a,hex(a) from t1;
281
alter table t1 change a a binary(4);
282
select a,hex(a) from t1;
283
alter table t1 change a a char(10) character set cp1251;
284
select a,hex(a) from t1;
285
alter table t1 change a a char(10) character set koi8r;
286
select a,hex(a) from t1;
287
alter table t1 change a a varchar(10) character set cp1251;
288
select a,hex(a) from t1;
289
alter table t1 change a a char(10) character set koi8r;
290
select a,hex(a) from t1;
291
alter table t1 change a a text character set cp1251;
292
select a,hex(a) from t1;
293
alter table t1 change a a char(10) character set koi8r;
294
select a,hex(a) from t1;
298
# Test ALTER TABLE .. CHARACTER SET ..
300
show create table t1;
301
alter table t1 DEFAULT CHARACTER SET latin1;
302
show create table t1;
303
alter table t1 CONVERT TO CHARACTER SET latin1;
304
show create table t1;
305
alter table t1 DEFAULT CHARACTER SET cp1251;
306
show create table t1;
312
# Test that table CHARACTER SET does not affect blobs
314
create table t1 (myblob longblob,mytext longtext)
315
default charset latin1 collate latin1_general_cs;
316
show create table t1;
317
alter table t1 character set latin2;
318
show create table t1;
322
# Bug 2361 (Don't drop UNIQUE with DROP PRIMARY KEY)
325
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE);
326
ALTER TABLE t1 DROP PRIMARY KEY;
327
SHOW CREATE TABLE t1;
328
--error ER_CANT_DROP_FIELD_OR_KEY
329
ALTER TABLE t1 DROP PRIMARY KEY;
333
create table t1 (a int, b int, key(a));
334
insert into t1 values (1,1), (2,2);
335
--error ER_CANT_DROP_FIELD_OR_KEY
336
alter table t1 drop key no_such_key;
337
alter table t1 drop key a;
341
# BUG 12207 alter table ... discard table space on MyISAM table causes ERROR 2013 (HY000)
343
# Some platforms (Mac OS X, Windows) will send the error message using small letters.
344
CREATE TABLE T12207(a int) ENGINE=MYISAM;
345
--replace_result t12207 T12207
346
--error ER_ILLEGAL_HA
347
ALTER TABLE T12207 DISCARD TABLESPACE;
351
# Bug #6479 ALTER TABLE ... changing charset fails for TEXT columns
353
# The column's character set was changed but the actual data was not
354
# modified. In other words, the values were reinterpreted
355
# as UTF8 instead of being converted.
356
create table t1 (a text) character set koi8r;
357
insert into t1 values (_koi8r'ļæ½ļæ½ļæ½ļæ½');
358
select hex(a) from t1;
359
alter table t1 convert to character set cp1251;
360
select hex(a) from t1;
364
# Test for bug #7884 "Able to add invalid unique index on TIMESTAMP prefix"
365
# MySQL should not think that packed field with non-zero decimals is
366
# geometry field and allow to create prefix index which is
367
# shorter than packed field length.
369
create table t1 ( a timestamp );
370
--error ER_WRONG_SUB_KEY
371
alter table t1 add unique ( a(1) );
375
# Bug #24395: ALTER TABLE DISABLE KEYS doesn't work when modifying the table
377
# This problem happens if the data change is compatible.
378
# Changing to the same type is compatible for example.
381
drop table if exists t1;
383
create table t1 (a int, key(a));
384
show indexes from t1;
385
--echo "this used not to disable the index"
386
alter table t1 modify a int, disable keys;
387
show indexes from t1;
389
alter table t1 enable keys;
390
show indexes from t1;
392
alter table t1 modify a bigint, disable keys;
393
show indexes from t1;
395
alter table t1 enable keys;
396
show indexes from t1;
398
alter table t1 add b char(10), disable keys;
399
show indexes from t1;
401
alter table t1 add c decimal(10,2), enable keys;
402
show indexes from t1;
404
--echo "this however did"
405
alter table t1 disable keys;
406
show indexes from t1;
410
alter table t1 add d decimal(15,5);
411
--echo "The key should still be disabled"
412
show indexes from t1;
416
--echo "Now will test with one unique index"
417
create table t1(a int, b char(10), unique(a));
418
show indexes from t1;
419
alter table t1 disable keys;
420
show indexes from t1;
421
alter table t1 enable keys;
423
--echo "If no copy on noop change, this won't touch the data file"
424
--echo "Unique index, no change"
425
alter table t1 modify a int, disable keys;
426
show indexes from t1;
428
--echo "Change the type implying data copy"
429
--echo "Unique index, no change"
430
alter table t1 modify a bigint, disable keys;
431
show indexes from t1;
433
alter table t1 modify a bigint;
434
show indexes from t1;
436
alter table t1 modify a int;
437
show indexes from t1;
441
--echo "Now will test with one unique and one non-unique index"
442
create table t1(a int, b char(10), unique(a), key(b));
443
show indexes from t1;
444
alter table t1 disable keys;
445
show indexes from t1;
446
alter table t1 enable keys;
449
--echo "If no copy on noop change, this won't touch the data file"
450
--echo "The non-unique index will be disabled"
451
alter table t1 modify a int, disable keys;
452
show indexes from t1;
453
alter table t1 enable keys;
454
show indexes from t1;
456
--echo "Change the type implying data copy"
457
--echo "The non-unique index will be disabled"
458
alter table t1 modify a bigint, disable keys;
459
show indexes from t1;
461
--echo "Change again the type, but leave the indexes as_is"
462
alter table t1 modify a int;
463
show indexes from t1;
464
--echo "Try the same. When data is no copied on similar tables, this is noop"
465
alter table t1 modify a int;
466
show indexes from t1;
472
# Bug#11493 - Alter table rename to default database does not work without
475
create database mysqltest;
476
create table t1 (c1 int);
477
# Move table to other database.
478
alter table t1 rename mysqltest.t1;
479
# Assure that it has moved.
480
--error ER_BAD_TABLE_ERROR
483
alter table mysqltest.t1 rename t1;
484
# Assure that it is back.
486
# Now test for correct message if no database is selected.
487
# Create t1 in 'test'.
488
create table t1 (c1 int);
489
# Change to other db.
491
# Drop the current db. This de-selects any db.
492
drop database mysqltest;
493
# Now test for correct message.
494
--error ER_NO_DB_ERROR
495
alter table test.t1 rename t1;
496
# Check that explicit qualifying works even with no selected db.
497
alter table test.t1 rename test.t1;
498
# Go back to standard 'test' db.
503
# BUG#23404 - ROW_FORMAT=FIXED option is lost is an index is added to the
506
CREATE TABLE t1(a INT) ROW_FORMAT=FIXED;
507
CREATE INDEX i1 ON t1(a);
508
SHOW CREATE TABLE t1;
510
SHOW CREATE TABLE t1;
514
# Bug#24219 - ALTER TABLE ... RENAME TO ... , DISABLE KEYS leads to crash
517
DROP TABLE IF EXISTS bug24219;
518
DROP TABLE IF EXISTS bug24219_2;
521
CREATE TABLE bug24219 (a INT, INDEX(a));
523
SHOW INDEX FROM bug24219;
525
ALTER TABLE bug24219 RENAME TO bug24219_2, DISABLE KEYS;
527
SHOW INDEX FROM bug24219_2;
529
DROP TABLE bug24219_2;
532
# Bug#24562 (ALTER TABLE ... ORDER BY ... with complex expression asserts)
536
drop table if exists table_24562;
539
create table table_24562(
544
insert into table_24562 values
545
(1, 0, "Introduction"),
547
(1, 2, "Acknowledgements"),
552
(3, 0, "Intermediate"),
553
(3, 1, "Complex queries"),
554
(3, 2, "Stored Procedures"),
555
(3, 3, "Stored Functions"),
557
(4, 1, "Replication"),
558
(4, 2, "Load balancing"),
559
(4, 3, "High availability"),
560
(5, 0, "Conclusion");
562
select * from table_24562;
564
alter table table_24562 add column reviewer varchar(20),
567
select * from table_24562;
569
update table_24562 set reviewer="Me" where section=2;
570
update table_24562 set reviewer="You" where section=3;
572
alter table table_24562
573
order by section ASC, subsection DESC;
575
select * from table_24562;
577
alter table table_24562
578
order by table_24562.subsection ASC, table_24562.section DESC;
580
select * from table_24562;
582
--error ER_PARSE_ERROR
583
alter table table_24562 order by 12;
584
--error ER_PARSE_ERROR
585
alter table table_24562 order by (section + 12);
586
--error ER_PARSE_ERROR
587
alter table table_24562 order by length(title);
588
--error ER_PARSE_ERROR
589
alter table table_24562 order by (select 12 from dual);
591
--error ER_BAD_FIELD_ERROR
592
alter table table_24562 order by no_such_col;
594
drop table table_24562;
599
# Bug #14693 (ALTER SET DEFAULT doesn't work)
602
create table t1 (mycol int(10) not null);
603
alter table t1 alter column mycol set default 0;
608
# Bug#25262 Auto Increment lost when changing Engine type
611
create table t1(id int(8) primary key auto_increment) engine=heap;
613
insert into t1 values (null);
614
insert into t1 values (null);
618
# Set auto increment to 50
619
alter table t1 auto_increment = 50;
622
alter table t1 engine = myisam;
624
# This insert should get id 50
625
insert into t1 values (null);
628
# Alter to heap again
629
alter table t1 engine = heap;
630
insert into t1 values (null);
636
# Bug#27507: Wrong DATETIME value was allowed by ALTER TABLE in the
639
set @orig_sql_mode = @@sql_mode;
640
set sql_mode="no_zero_date";
641
create table t1(f1 int);
642
alter table t1 add column f2 datetime not null, add column f21 date not null;
643
insert into t1 values(1,'2000-01-01','2000-01-01');
645
alter table t1 add column f3 datetime not null;
647
alter table t1 add column f3 date not null;
649
alter table t1 add column f4 datetime not null default '2002-02-02',
650
add column f41 date not null;
651
alter table t1 add column f4 datetime not null default '2002-02-02',
652
add column f41 date not null default '2002-02-02';
655
set sql_mode= @orig_sql_mode;
658
# Some additional tests for new, faster alter table. Note that most of the
659
# whole alter table code is being tested all around the test suite already.
662
create table t1 (v varchar(32));
663
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
665
# Fast alter, no copy performed
666
alter table t1 change v v2 varchar(32);
668
# Fast alter, no copy performed
669
alter table t1 change v2 v varchar(64);
671
update t1 set v = 'lmn' where v = 'hij';
673
# Regular alter table
674
alter table t1 add i int auto_increment not null primary key first;
676
update t1 set i=5 where i=3;
678
alter table t1 change i i bigint;
680
alter table t1 add unique key (i, v);
681
select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
685
# Bug#6073 "ALTER table minor glich": ALTER TABLE complains that an index
686
# without # prefix is not allowed for TEXT columns, while index
687
# is defined with prefix.
689
create table t1 (t varchar(255) default null, key t (t(80)))
690
engine=myisam default charset=latin1;
691
alter table t1 change t t text;
695
# Bug #26794: Adding an index with a prefix on a SPATIAL type breaks ALTER
698
CREATE TABLE t1 (a varchar(500));
700
ALTER TABLE t1 ADD b GEOMETRY NOT NULL, ADD SPATIAL INDEX(b);
701
SHOW CREATE TABLE t1;
702
ALTER TABLE t1 ADD KEY(b(50));
703
SHOW CREATE TABLE t1;
705
ALTER TABLE t1 ADD c POINT;
706
SHOW CREATE TABLE t1;
708
--error ER_WRONG_SUB_KEY
709
CREATE TABLE t2 (a INT, KEY (a(20)));
711
ALTER TABLE t1 ADD d INT;
712
--error ER_WRONG_SUB_KEY
713
ALTER TABLE t1 ADD KEY (d(20));
715
# the 5.1 part of the test
716
--error ER_WRONG_SUB_KEY
717
ALTER TABLE t1 ADD e GEOMETRY NOT NULL, ADD SPATIAL KEY (e(30));
722
# Bug#18038 MySQL server corrupts binary columns data
725
CREATE TABLE t1 (s CHAR(8) BINARY);
726
INSERT INTO t1 VALUES ('test');
727
SELECT LENGTH(s) FROM t1;
728
ALTER TABLE t1 MODIFY s CHAR(10) BINARY;
729
SELECT LENGTH(s) FROM t1;
732
CREATE TABLE t1 (s BINARY(8));
733
INSERT INTO t1 VALUES ('test');
734
SELECT LENGTH(s) FROM t1;
735
SELECT HEX(s) FROM t1;
736
ALTER TABLE t1 MODIFY s BINARY(10);
737
SELECT HEX(s) FROM t1;
738
SELECT LENGTH(s) FROM t1;
742
# Bug#19386: Multiple alter causes crashed table
743
# The trailing column would get corrupted data, or server could not even read
747
CREATE TABLE t1 (v VARCHAR(3), b INT);
748
INSERT INTO t1 VALUES ('abc', 5);
750
ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4);
756
# Bug#31291 ALTER TABLE CONVERT TO CHARACTER SET does not change some data types
758
create table t1 (a tinytext character set latin1);
759
alter table t1 convert to character set utf8;
760
show create table t1;
762
create table t1 (a mediumtext character set latin1);
763
alter table t1 convert to character set utf8;
764
show create table t1;
767
--echo End of 5.0 tests
770
# Extended test coverage for ALTER TABLE behaviour under LOCK TABLES
771
# It should be consistent across all platforms and for all engines
772
# (Before 5.1 this was not true as behavior was different between
773
# Unix/Windows and transactional/non-transactional tables).
774
# See also innodb_mysql.test
777
drop table if exists t1, t2, t3;
779
create table t1 (i int);
780
create table t3 (j int);
781
insert into t1 values ();
782
insert into t3 values ();
783
# Table which is altered under LOCK TABLES it should stay in list of locked
784
# tables and be available after alter takes place unless ALTER contains RENAME
785
# clause. We should see the new definition of table, of course.
786
lock table t1 write, t3 read;
787
# Example of so-called 'fast' ALTER TABLE
788
alter table t1 modify i int default 1;
789
insert into t1 values ();
791
# And now full-blown ALTER TABLE
792
alter table t1 change i c char(10) default "Two";
793
insert into t1 values ();
795
# If table is renamed then it should be removed from the list
796
# of locked tables. 'Fast' ALTER TABLE with RENAME clause:
797
alter table t1 modify c char(10) default "Three", rename to t2;
798
--error ER_TABLE_NOT_LOCKED
800
--error ER_TABLE_NOT_LOCKED
804
insert into t2 values ();
806
lock table t2 write, t3 read;
807
# Full ALTER TABLE with RENAME
808
alter table t2 change c vc varchar(100) default "Four", rename to t1;
809
--error ER_TABLE_NOT_LOCKED
811
--error ER_TABLE_NOT_LOCKED
815
insert into t1 values ();
821
# Bug#18775 - Temporary table from alter table visible to other threads
823
# Check if special characters work and duplicates are detected.
825
DROP TABLE IF EXISTS `t+1`, `t+2`;
827
CREATE TABLE `t+1` (c1 INT);
828
ALTER TABLE `t+1` RENAME `t+2`;
829
CREATE TABLE `t+1` (c1 INT);
830
--error ER_TABLE_EXISTS_ERROR
831
ALTER TABLE `t+1` RENAME `t+2`;
832
DROP TABLE `t+1`, `t+2`;
834
# Same for temporary tables though these names do not become file names.
835
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
836
ALTER TABLE `tt+1` RENAME `tt+2`;
837
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
838
--error ER_TABLE_EXISTS_ERROR
839
ALTER TABLE `tt+1` RENAME `tt+2`;
840
SHOW CREATE TABLE `tt+1`;
841
SHOW CREATE TABLE `tt+2`;
842
DROP TABLE `tt+1`, `tt+2`;
844
# Check if special characters as in tmp_file_prefix work.
845
CREATE TABLE `#sql1` (c1 INT);
846
CREATE TABLE `@0023sql2` (c1 INT);
848
RENAME TABLE `#sql1` TO `@0023sql1`;
849
RENAME TABLE `@0023sql2` TO `#sql2`;
851
ALTER TABLE `@0023sql1` RENAME `#sql-1`;
852
ALTER TABLE `#sql2` RENAME `@0023sql-2`;
854
INSERT INTO `#sql-1` VALUES (1);
855
INSERT INTO `@0023sql-2` VALUES (2);
856
DROP TABLE `#sql-1`, `@0023sql-2`;
858
# Same for temporary tables though these names do not become file names.
859
CREATE TEMPORARY TABLE `#sql1` (c1 INT);
860
CREATE TEMPORARY TABLE `@0023sql2` (c1 INT);
862
ALTER TABLE `#sql1` RENAME `@0023sql1`;
863
ALTER TABLE `@0023sql2` RENAME `#sql2`;
865
INSERT INTO `#sql2` VALUES (1);
866
INSERT INTO `@0023sql1` VALUES (2);
867
SHOW CREATE TABLE `#sql2`;
868
SHOW CREATE TABLE `@0023sql1`;
869
DROP TABLE `#sql2`, `@0023sql1`;
872
# Bug #22369: Alter table rename combined with other alterations causes lost tables
874
# This problem happens if the data change is compatible.
875
# Changing to the same type is compatible for example.
878
DROP TABLE IF EXISTS t1;
879
DROP TABLE IF EXISTS t2;
882
int_field INTEGER UNSIGNED NOT NULL,
889
SHOW INDEXES FROM t1;
891
INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet");
892
--echo "Non-copy data change - new frm, but old data and index files"
894
CHANGE int_field unsigned_int_field INTEGER UNSIGNED NOT NULL,
897
--error ER_NO_SUCH_TABLE
898
SELECT * FROM t1 ORDER BY int_field;
899
SELECT * FROM t2 ORDER BY unsigned_int_field;
902
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT UNSIGNED NOT NULL;
908
# Bug#28427: Columns were renamed instead of moving by ALTER TABLE.
910
CREATE TABLE t1 (f1 INT, f2 INT, f3 INT);
911
INSERT INTO t1 VALUES (1, 2, NULL);
913
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f1;
915
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2;
920
# BUG#29957 - alter_table.test fails
922
create table t1 (c char(10) default "Two");
924
insert into t1 values ();
925
alter table t1 modify c char(10) default "Three";
932
# Bug#33873: Fast ALTER TABLE doesn't work with multibyte character sets
936
DROP TABLE IF EXISTS t1;
938
CREATE TABLE t1 (id int, c int) character set latin1;
939
INSERT INTO t1 VALUES (1,1);
941
ALTER TABLE t1 CHANGE c d int;
942
ALTER TABLE t1 CHANGE d c int;
943
ALTER TABLE t1 MODIFY c VARCHAR(10);
944
ALTER TABLE t1 CHANGE c d varchar(10);
945
ALTER TABLE t1 CHANGE d c varchar(10);
950
DROP TABLE IF EXISTS t1;
952
CREATE TABLE t1 (id int, c int) character set utf8;
953
INSERT INTO t1 VALUES (1,1);
955
ALTER TABLE t1 CHANGE c d int;
956
ALTER TABLE t1 CHANGE d c int;
957
ALTER TABLE t1 MODIFY c VARCHAR(10);
958
ALTER TABLE t1 CHANGE c d varchar(10);
959
ALTER TABLE t1 CHANGE d c varchar(10);
964
# Bug#39372 "Smart" ALTER TABLE not so smart after all.
966
create table t1(f1 int not null, f2 int not null, key (f1), key (f2));
971
EVAL insert into t1 values (1,1),(1,1),(1,1),(1,1),(1,1);
972
EVAL insert into t1 values (2,2),(2,2),(2,2),(2,2),(2,2);
977
select index_length into @unpaked_keys_size from
978
information_schema.tables where table_name='t1';
979
alter table t1 pack_keys=1;
980
select index_length into @paked_keys_size from
981
information_schema.tables where table_name='t1';
982
select (@unpaked_keys_size > @paked_keys_size);
984
select max_data_length into @orig_max_data_length from
985
information_schema.tables where table_name='t1';
986
alter table t1 max_rows=100;
987
select max_data_length into @changed_max_data_length from
988
information_schema.tables where table_name='t1';
989
select (@orig_max_data_length > @changed_max_data_length);
994
# Bug #23113: Different behavior on altering ENUM fields between 5.0 and 5.1
996
CREATE TABLE t1(a INT AUTO_INCREMENT PRIMARY KEY,
997
b ENUM('a', 'b', 'c') NOT NULL);
998
INSERT INTO t1 (b) VALUES ('a'), ('c'), ('b'), ('b'), ('a');
999
ALTER TABLE t1 MODIFY b ENUM('a', 'z', 'b', 'c') NOT NULL;
1004
--echo # Bug#45567: Fast ALTER TABLE broken for enum and set
1008
DROP TABLE IF EXISTS t1;
1011
CREATE TABLE t1 (a ENUM('a1','a2'));
1012
INSERT INTO t1 VALUES ('a1'),('a2');
1014
--echo # No copy: No modification
1015
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2');
1016
--echo # No copy: Add new enumeration to the end
1017
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a3');
1018
--echo # Copy: Modify and add new to the end
1019
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','xx','a5');
1020
--echo # Copy: Remove from the end
1021
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','xx');
1022
--echo # Copy: Add new enumeration
1023
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a0','xx');
1024
--echo # No copy: Add new enumerations to the end
1025
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a0','xx','a5','a6');
1029
CREATE TABLE t1 (a SET('a1','a2'));
1030
INSERT INTO t1 VALUES ('a1'),('a2');
1032
--echo # No copy: No modification
1033
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2');
1034
--echo # No copy: Add new to the end
1035
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a3');
1036
--echo # Copy: Modify and add new to the end
1037
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','xx','a5');
1038
--echo # Copy: Remove from the end
1039
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','xx');
1040
--echo # Copy: Add new member
1041
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx');
1042
--echo # No copy: Add new to the end
1043
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx','a5','a6');
1044
--echo # Copy: Numerical incrase (pack lenght)
1045
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx','a5','a6','a7','a8','a9','a10');
1050
# Bug#43508: Renaming timestamp or date column triggers table copy
1053
CREATE TABLE t1 (f1 TIMESTAMP NULL DEFAULT NULL,
1054
f2 INT(11) DEFAULT NULL) ENGINE=MYISAM DEFAULT CHARSET=utf8;
1056
INSERT INTO t1 VALUES (NULL, NULL), ("2009-10-09 11:46:19", 2);
1058
--echo this should affect no rows as there is no real change
1060
ALTER TABLE t1 CHANGE COLUMN f1 f1_no_real_change TIMESTAMP NULL DEFAULT NULL;
1066
--echo # Bug #31145: ALTER TABLE DROP COLUMN, ADD COLUMN crashes (linux)
1067
--echo # or freezes (win) the server
1070
CREATE TABLE t1 (a TEXT, id INT, b INT);
1071
ALTER TABLE t1 DROP COLUMN a, ADD COLUMN c TEXT FIRST;
1077
--echo # Test for bug #12652385 - "61493: REORDERING COLUMNS TO POSITION
1078
--echo # FIRST CAN CAUSE DATA TO BE CORRUPTED".
1081
drop table if exists t1;
1083
--echo # Use MyISAM engine as the fact that InnoDB doesn't support
1084
--echo # in-place ALTER TABLE in cases when columns are being renamed
1085
--echo # hides some bugs.
1086
create table t1 (i int, j int) engine=myisam;
1087
insert into t1 value (1, 2);
1088
--echo # First, test for original problem described in the bug report.
1090
--echo # Change of column order by the below ALTER TABLE statement should
1091
--echo # affect both column names and column contents.
1092
alter table t1 modify column j int first;
1094
--echo # Now test for similar problem with the same root.
1095
--echo # The below ALTER TABLE should change not only the name but
1096
--echo # also the value for the last column of the table.
1097
alter table t1 drop column i, add column k int default 0;
1103
--echo End of 5.1 tests
1106
# Bug #31031 ALTER TABLE regression in 5.0
1108
# The ALTER TABLE operation failed with
1109
# ERROR 1089 (HY000): Incorrect sub part key; ...
1111
CREATE TABLE t1(c CHAR(10),
1112
i INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY);
1113
INSERT INTO t1 VALUES('a',2),('b',4),('c',6);
1116
ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT,
1122
# Bug#50542 5.5.x doesn't check length of key prefixes:
1123
# corruption and crash results
1125
# This case is related to Bug#31031 (above)
1126
# A statement where the index key is larger/wider than
1127
# the column type, should cause an error
1129
--error ER_WRONG_SUB_KEY
1130
CREATE TABLE t1 (a CHAR(1), PRIMARY KEY (a(255)));
1132
# Test other variants of creating indices
1133
CREATE TABLE t1 (a CHAR(1));
1135
--error ER_WRONG_SUB_KEY
1136
ALTER TABLE t1 ADD PRIMARY KEY (a(20));
1137
--error ER_WRONG_SUB_KEY
1138
ALTER TABLE t1 ADD KEY (a(20));
1140
--error ER_WRONG_SUB_KEY
1141
CREATE UNIQUE INDEX i1 ON t1 (a(20));
1142
--error ER_WRONG_SUB_KEY
1143
CREATE INDEX i2 ON t1 (a(20));
1149
# Bug #45052 ALTER TABLE ADD COLUMN crashes server with multiple foreign key columns
1150
# The alter table fails if 2 or more new fields added and
1151
# also added a key with these fields
1153
CREATE TABLE t1 (id int);
1154
INSERT INTO t1 VALUES (1), (2);
1155
ALTER TABLE t1 ADD COLUMN (f1 INT), ADD COLUMN (f2 INT), ADD KEY f2k(f2);
1160
--echo # Test for bug #53820 "ALTER a MEDIUMINT column table causes full
1161
--echo # table copy".
1164
DROP TABLE IF EXISTS t1;
1166
CREATE TABLE t1 (a INT, b MEDIUMINT);
1167
INSERT INTO t1 VALUES (1, 1), (2, 2);
1168
--echo # The below ALTER should not copy table and so no rows should
1169
--echo # be shown as affected.
1171
ALTER TABLE t1 CHANGE a id INT;
1177
--echo # Bug#11754461 CANNOT ALTER TABLE WHEN KEY PREFIX TOO LONG
1181
DROP DATABASE IF EXISTS db1;
1184
CREATE DATABASE db1 CHARACTER SET utf8;
1185
CREATE TABLE db1.t1 (bar TINYTEXT, KEY (bar(100)));
1186
ALTER TABLE db1.t1 ADD baz INT;
1191
--echo # Additional coverage for refactoring which is made as part
1192
--echo # of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
1193
--echo # to allow temp table operations".
1195
--echo # At some point the below test case failed on assertion.
1198
DROP TABLE IF EXISTS t1;
1201
CREATE TEMPORARY TABLE t1 (i int) ENGINE=MyISAM;
1203
--error ER_ILLEGAL_HA
1204
ALTER TABLE t1 DISCARD TABLESPACE;
1210
--echo # Bug#11938039 RE-EXECUTION OF FRM-ONLY ALTER TABLE WITH RENAME
1211
--echo # CLAUSE FAILS OR ABORTS SERVER.
1214
drop table if exists t1;
1216
create table t1 (a int);
1217
prepare stmt1 from 'alter table t1 alter column a set default 1, rename to t2';
1219
rename table t2 to t1;
1220
--echo # The below statement should succeed and not emit error or abort server.
1222
deallocate prepare stmt1;
1227
--echo # Bug#11938817 ALTER BEHAVIOR DIFFERENT THEN DOCUMENTED
1231
DROP TABLE IF EXISTS t1;
1234
CREATE TABLE t1(a INT) engine=innodb;
1235
INSERT INTO t1 VALUES (1), (2);
1238
--echo # This should not do anything
1240
--echo # Check that we rebuild the table
1241
ALTER TABLE t1 engine=innodb;
1242
--echo # This should also rebuild the table
1243
ALTER TABLE t1 FORCE;
1248
--echo # Bug#11748057 (formerly known as 34972): ALTER TABLE statement doesn't
1249
--echo # identify correct column name.
1252
CREATE TABLE t1 (c1 int unsigned , c2 char(100) not null default '');
1253
ALTER TABLE t1 ADD c3 char(16) NOT NULL DEFAULT '' AFTER c2,
1254
MODIFY c2 char(100) NOT NULL DEFAULT '' AFTER c1;
1255
SHOW CREATE TABLE t1;
1260
--echo # WL#5534 Online ALTER, Phase 1
1263
--echo # Single thread tests.
1264
--echo # See innodb_mysql_sync.test for multi thread tests.
1267
DROP TABLE IF EXISTS t1;
1270
CREATE TABLE t1(a INT PRIMARY KEY, b INT) engine=InnoDB;
1271
CREATE TABLE m1(a INT PRIMARY KEY, b INT) engine=MyISAM;
1272
INSERT INTO t1 VALUES (1,1), (2,2);
1273
INSERT INTO m1 VALUES (1,1), (2,2);
1276
--echo # 1: Test ALGORITHM keyword
1279
--echo # --enable_info allows us to see how many rows were updated
1280
--echo # by ALTER TABLE. in-place will show 0 rows, while copy > 0.
1283
ALTER TABLE t1 ADD INDEX i1(b);
1284
ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT;
1285
ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= COPY;
1286
ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= INPLACE;
1287
--error ER_UNKNOWN_ALTER_ALGORITHM
1288
ALTER TABLE t1 ADD INDEX i5(b), ALGORITHM= INVALID;
1290
ALTER TABLE m1 ENABLE KEYS;
1291
ALTER TABLE m1 ENABLE KEYS, ALGORITHM= DEFAULT;
1292
ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY;
1293
ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE;
1296
ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4;
1299
--echo # 2: Test ALGORITHM + old_alter_table
1303
SET SESSION old_alter_table= 1;
1304
ALTER TABLE t1 ADD INDEX i1(b);
1305
ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT;
1306
ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= COPY;
1307
ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= INPLACE;
1308
SET SESSION old_alter_table= 0;
1311
ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4;
1314
--echo # 3: Test unsupported in-place operation
1317
ALTER TABLE t1 ADD COLUMN (c1 INT);
1318
ALTER TABLE t1 ADD COLUMN (c2 INT), ALGORITHM= DEFAULT;
1319
ALTER TABLE t1 ADD COLUMN (c3 INT), ALGORITHM= COPY;
1320
ALTER TABLE t1 ADD COLUMN (c4 INT), ALGORITHM= INPLACE;
1322
ALTER TABLE t1 DROP COLUMN c1, DROP COLUMN c2, DROP COLUMN c3, DROP COLUMN c4;
1325
--echo # 4: Test LOCK keyword
1329
ALTER TABLE t1 ADD INDEX i1(b), LOCK= DEFAULT;
1330
ALTER TABLE t1 ADD INDEX i2(b), LOCK= NONE;
1331
ALTER TABLE t1 ADD INDEX i3(b), LOCK= SHARED;
1332
ALTER TABLE t1 ADD INDEX i4(b), LOCK= EXCLUSIVE;
1333
--error ER_UNKNOWN_ALTER_LOCK
1334
ALTER TABLE t1 ADD INDEX i5(b), LOCK= INVALID;
1337
ALTER TABLE m1 ENABLE KEYS, LOCK= DEFAULT;
1338
--error ER_ALTER_OPERATION_NOT_SUPPORTED
1339
ALTER TABLE m1 ENABLE KEYS, LOCK= NONE;
1340
--error ER_ALTER_OPERATION_NOT_SUPPORTED
1341
ALTER TABLE m1 ENABLE KEYS, LOCK= SHARED;
1342
ALTER TABLE m1 ENABLE KEYS, LOCK= EXCLUSIVE;
1344
ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4;
1347
--echo # 5: Test ALGORITHM + LOCK
1351
ALTER TABLE t1 ADD INDEX i1(b), ALGORITHM= INPLACE, LOCK= NONE;
1352
ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= INPLACE, LOCK= SHARED;
1353
ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= INPLACE, LOCK= EXCLUSIVE;
1354
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
1355
ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= COPY, LOCK= NONE;
1356
ALTER TABLE t1 ADD INDEX i5(b), ALGORITHM= COPY, LOCK= SHARED;
1357
ALTER TABLE t1 ADD INDEX i6(b), ALGORITHM= COPY, LOCK= EXCLUSIVE;
1359
--error ER_ALTER_OPERATION_NOT_SUPPORTED
1360
ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= NONE;
1361
--error ER_ALTER_OPERATION_NOT_SUPPORTED
1362
ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= SHARED;
1363
ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= EXCLUSIVE;
1364
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
1365
ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= NONE;
1366
# This works because the lock will be SNW for the copy phase.
1367
# It will still require exclusive lock for actually enabling keys.
1368
ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= SHARED;
1369
ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= EXCLUSIVE;
1375
--echo # 6: Possible deadlock involving thr_lock.c
1378
CREATE TABLE t1(a INT PRIMARY KEY, b INT);
1379
INSERT INTO t1 VALUES (1,1), (2,2);
1382
INSERT INTO t1 VALUES (3,3);
1384
--echo # Connection con1
1385
connect (con1, localhost, root);
1387
--send ALTER TABLE t1 DISABLE KEYS
1389
--echo # Connection default
1391
--echo # Waiting until ALTER TABLE is blocked.
1392
let $wait_condition=
1393
SELECT COUNT(*) = 1 FROM information_schema.processlist
1394
WHERE state = "Waiting for table metadata lock" AND
1395
info = "ALTER TABLE t1 DISABLE KEYS";
1396
--source include/wait_condition.inc
1397
UPDATE t1 SET b = 4;
1400
--echo # Connection con1
1402
--echo # Reaping: ALTER TABLE t1 DISABLE KEYS
1405
--source include/wait_until_disconnected.inc
1407
--echo # Connection default
1412
--echo # 7: Which operations require copy and which can be done in-place?
1414
--echo # Test which ALTER TABLE operations are done in-place and
1415
--echo # which operations are done using temporary table copy.
1417
--echo # --enable_info allows us to see how many rows were updated
1418
--echo # by ALTER TABLE. in-place will show 0 rows, while copy > 0.
1422
DROP TABLE IF EXISTS ti1, ti2, ti3, tm1, tm2, tm3;
1425
--echo # Single operation tests
1427
CREATE TABLE ti1(a INT NOT NULL, b INT, c INT) engine=InnoDB;
1428
CREATE TABLE tm1(a INT NOT NULL, b INT, c INT) engine=MyISAM;
1429
CREATE TABLE ti2(a INT PRIMARY KEY AUTO_INCREMENT, b INT, c INT) engine=InnoDB;
1430
CREATE TABLE tm2(a INT PRIMARY KEY AUTO_INCREMENT, b INT, c INT) engine=MyISAM;
1431
INSERT INTO ti1 VALUES (1,1,1), (2,2,2);
1432
INSERT INTO ti2 VALUES (1,1,1), (2,2,2);
1433
INSERT INTO tm1 VALUES (1,1,1), (2,2,2);
1434
INSERT INTO tm2 VALUES (1,1,1), (2,2,2);
1440
ALTER TABLE ti1 ADD COLUMN d VARCHAR(200);
1441
ALTER TABLE tm1 ADD COLUMN d VARCHAR(200);
1442
ALTER TABLE ti1 ADD COLUMN d2 VARCHAR(200);
1443
ALTER TABLE tm1 ADD COLUMN d2 VARCHAR(200);
1444
ALTER TABLE ti1 ADD COLUMN e ENUM('a', 'b') FIRST;
1445
ALTER TABLE tm1 ADD COLUMN e ENUM('a', 'b') FIRST;
1446
ALTER TABLE ti1 ADD COLUMN f INT AFTER a;
1447
ALTER TABLE tm1 ADD COLUMN f INT AFTER a;
1449
ALTER TABLE ti1 ADD INDEX ii1(b);
1450
ALTER TABLE tm1 ADD INDEX im1(b);
1451
ALTER TABLE ti1 ADD UNIQUE INDEX ii2 (c);
1452
ALTER TABLE tm1 ADD UNIQUE INDEX im2 (c);
1453
ALTER TABLE ti1 ADD FULLTEXT INDEX ii3 (d);
1454
ALTER TABLE tm1 ADD FULLTEXT INDEX im3 (d);
1455
ALTER TABLE ti1 ADD FULLTEXT INDEX ii4 (d2);
1456
ALTER TABLE tm1 ADD FULLTEXT INDEX im4 (d2);
1458
# Bug#14140038 INCONSISTENT HANDLING OF FULLTEXT INDEXES IN ALTER TABLE
1459
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
1460
ALTER TABLE ti1 ADD PRIMARY KEY(a), ALGORITHM=INPLACE;
1461
ALTER TABLE ti1 ADD PRIMARY KEY(a);
1462
ALTER TABLE tm1 ADD PRIMARY KEY(a);
1464
ALTER TABLE ti1 DROP INDEX ii3;
1465
ALTER TABLE tm1 DROP INDEX im3;
1467
ALTER TABLE ti1 DROP COLUMN d2;
1468
ALTER TABLE tm1 DROP COLUMN d2;
1470
ALTER TABLE ti1 ADD CONSTRAINT fi1 FOREIGN KEY (b) REFERENCES ti2(a);
1471
ALTER TABLE tm1 ADD CONSTRAINT fm1 FOREIGN KEY (b) REFERENCES tm2(a);
1473
ALTER TABLE ti1 ALTER COLUMN b SET DEFAULT 1;
1474
ALTER TABLE tm1 ALTER COLUMN b SET DEFAULT 1;
1475
ALTER TABLE ti1 ALTER COLUMN b DROP DEFAULT;
1476
ALTER TABLE tm1 ALTER COLUMN b DROP DEFAULT;
1478
# This will set both ALTER_COLUMN_NAME and COLUMN_DEFAULT_VALUE
1479
ALTER TABLE ti1 CHANGE COLUMN f g INT;
1480
ALTER TABLE tm1 CHANGE COLUMN f g INT;
1481
ALTER TABLE ti1 CHANGE COLUMN g h VARCHAR(20);
1482
ALTER TABLE tm1 CHANGE COLUMN g h VARCHAR(20);
1483
ALTER TABLE ti1 MODIFY COLUMN e ENUM('a', 'b', 'c');
1484
ALTER TABLE tm1 MODIFY COLUMN e ENUM('a', 'b', 'c');
1485
ALTER TABLE ti1 MODIFY COLUMN e INT;
1486
ALTER TABLE tm1 MODIFY COLUMN e INT;
1487
# This will set both ALTER_COLUMN_ORDER and COLUMN_DEFAULT_VALUE
1488
ALTER TABLE ti1 MODIFY COLUMN e INT AFTER h;
1489
ALTER TABLE tm1 MODIFY COLUMN e INT AFTER h;
1490
ALTER TABLE ti1 MODIFY COLUMN e INT FIRST;
1491
ALTER TABLE tm1 MODIFY COLUMN e INT FIRST;
1492
# This will set both ALTER_COLUMN_NOT_NULLABLE and COLUMN_DEFAULT_VALUE
1494
# NULL -> NOT NULL only allowed INPLACE if strict sql_mode is on.
1495
SET @orig_sql_mode = @@sql_mode;
1496
SET @@sql_mode = 'STRICT_TRANS_TABLES';
1498
ALTER TABLE ti1 MODIFY COLUMN c INT NOT NULL;
1500
SET @@sql_mode = @orig_sql_mode;
1502
ALTER TABLE tm1 MODIFY COLUMN c INT NOT NULL;
1503
# This will set both ALTER_COLUMN_NULLABLE and COLUMN_DEFAULT_VALUE
1504
ALTER TABLE ti1 MODIFY COLUMN c INT NULL;
1505
ALTER TABLE tm1 MODIFY COLUMN c INT NULL;
1506
# This will set both ALTER_COLUMN_EQUAL_PACK_LENGTH and COLUMN_DEFAULT_VALUE
1507
ALTER TABLE ti1 MODIFY COLUMN h VARCHAR(30);
1508
ALTER TABLE tm1 MODIFY COLUMN h VARCHAR(30);
1509
ALTER TABLE ti1 MODIFY COLUMN h VARCHAR(30) AFTER d;
1510
ALTER TABLE tm1 MODIFY COLUMN h VARCHAR(30) AFTER d;
1512
ALTER TABLE ti1 DROP COLUMN h;
1513
ALTER TABLE tm1 DROP COLUMN h;
1515
ALTER TABLE ti1 DROP INDEX ii2;
1516
ALTER TABLE tm1 DROP INDEX im2;
1517
ALTER TABLE ti1 DROP PRIMARY KEY;
1518
ALTER TABLE tm1 DROP PRIMARY KEY;
1520
ALTER TABLE ti1 DROP FOREIGN KEY fi1;
1521
ALTER TABLE tm1 DROP FOREIGN KEY fm1;
1523
ALTER TABLE ti1 RENAME TO ti3;
1524
ALTER TABLE tm1 RENAME TO tm3;
1525
ALTER TABLE ti3 RENAME TO ti1;
1526
ALTER TABLE tm3 RENAME TO tm1;
1528
ALTER TABLE ti1 ORDER BY b;
1529
ALTER TABLE tm1 ORDER BY b;
1531
ALTER TABLE ti1 CONVERT TO CHARACTER SET utf16;
1532
ALTER TABLE tm1 CONVERT TO CHARACTER SET utf16;
1533
ALTER TABLE ti1 DEFAULT CHARACTER SET utf8;
1534
ALTER TABLE tm1 DEFAULT CHARACTER SET utf8;
1536
ALTER TABLE ti1 FORCE;
1537
ALTER TABLE tm1 FORCE;
1539
ALTER TABLE ti1 AUTO_INCREMENT 3;
1540
ALTER TABLE tm1 AUTO_INCREMENT 3;
1541
ALTER TABLE ti1 AVG_ROW_LENGTH 10;
1542
ALTER TABLE tm1 AVG_ROW_LENGTH 10;
1543
ALTER TABLE ti1 CHECKSUM 1;
1544
ALTER TABLE tm1 CHECKSUM 1;
1545
ALTER TABLE ti1 COMMENT 'test';
1546
ALTER TABLE tm1 COMMENT 'test';
1547
ALTER TABLE ti1 MAX_ROWS 100;
1548
ALTER TABLE tm1 MAX_ROWS 100;
1549
ALTER TABLE ti1 MIN_ROWS 1;
1550
ALTER TABLE tm1 MIN_ROWS 1;
1551
ALTER TABLE ti1 PACK_KEYS 1;
1552
ALTER TABLE tm1 PACK_KEYS 1;
1555
DROP TABLE ti1, ti2, tm1, tm2;
1557
--echo # Tests of >1 operation (InnoDB)
1559
CREATE TABLE ti1(a INT PRIMARY KEY AUTO_INCREMENT, b INT) engine=InnoDB;
1560
INSERT INTO ti1(b) VALUES (1), (2);
1563
ALTER TABLE ti1 RENAME TO ti3, ADD INDEX ii1(b);
1565
ALTER TABLE ti3 DROP INDEX ii1, AUTO_INCREMENT 5;
1567
INSERT INTO ti3(b) VALUES (5);
1569
ALTER TABLE ti3 ADD INDEX ii1(b), AUTO_INCREMENT 7;
1571
INSERT INTO ti3(b) VALUES (7);
1577
--echo # 8: Scenario in which ALTER TABLE was returning an unwarranted
1578
--echo # ER_ILLEGAL_HA error at some point during work on this WL.
1581
CREATE TABLE tm1(i INT DEFAULT 1) engine=MyISAM;
1582
ALTER TABLE tm1 ADD INDEX ii1(i), ALTER COLUMN i DROP DEFAULT;
1586
--echo # Bug#11815557 60269: MYSQL SHOULD REJECT ATTEMPTS TO CREATE SYSTEM
1587
--echo # TABLES IN INCORRECT ENGINE
1589
--echo # Note: This test assumes that only MyISAM supports system tables.
1590
--echo # If other engines are made to support system tables,
1591
--echo # then this test needs to be updated
1595
--error ER_UNSUPPORTED_ENGINE
1596
ALTER TABLE db ENGINE=innodb;
1597
--error ER_UNSUPPORTED_ENGINE
1598
ALTER TABLE user ENGINE=memory;
1599
--error ER_UNSUPPORTED_ENGINE
1600
ALTER TABLE proc ENGINE=heap;
1601
--error ER_UNSUPPORTED_ENGINE
1602
ALTER TABLE func ENGINE=csv;
1603
--error ER_UNSUPPORTED_ENGINE
1604
ALTER TABLE event ENGINE=merge;
1605
--error ER_UNSUPPORTED_ENGINE
1606
ALTER TABLE servers ENGINE=innodb;
1607
--error ER_UNSUPPORTED_ENGINE
1608
ALTER TABLE procs_priv ENGINE=memory;
1609
--error ER_UNSUPPORTED_ENGINE
1610
ALTER TABLE tables_priv ENGINE=heap;
1611
--error ER_UNSUPPORTED_ENGINE
1612
ALTER TABLE columns_priv ENGINE=csv;
1613
--error ER_UNSUPPORTED_ENGINE
1614
ALTER TABLE time_zone ENGINE=merge;
1615
--error ER_UNSUPPORTED_ENGINE
1616
ALTER TABLE help_topic ENGINE=innodb;
1618
--error ER_UNSUPPORTED_ENGINE
1619
CREATE TABLE db (dummy int) ENGINE=innodb;
1620
--error ER_UNSUPPORTED_ENGINE
1621
CREATE TABLE user (dummy int) ENGINE=memory;
1622
--error ER_UNSUPPORTED_ENGINE
1623
CREATE TABLE proc (dummy int) ENGINE=heap;
1624
--error ER_UNSUPPORTED_ENGINE
1625
CREATE TABLE func (dummy int) ENGINE=csv;
1626
--error ER_UNSUPPORTED_ENGINE
1627
CREATE TABLE event (dummy int) ENGINE=merge;
1628
--error ER_UNSUPPORTED_ENGINE
1629
CREATE TABLE servers (dummy int) ENGINE=innodb;
1630
--error ER_UNSUPPORTED_ENGINE
1631
CREATE TABLE procs_priv (dummy int) ENGINE=memory;
1632
--error ER_UNSUPPORTED_ENGINE
1633
CREATE TABLE tables_priv (dummy int) ENGINE=heap;
1634
--error ER_UNSUPPORTED_ENGINE
1635
CREATE TABLE columns_priv (dummy int) ENGINE=csv;
1636
--error ER_UNSUPPORTED_ENGINE
1637
CREATE TABLE time_zone (dummy int) ENGINE=merge;
1638
--error ER_UNSUPPORTED_ENGINE
1639
CREATE TABLE help_topic (dummy int) ENGINE=innodb;
1641
--echo # End of Bug#11815557