167
# Test ALTER TABLE ENABLE/DISABLE keys when things are locked
171
Host varchar(16) binary NOT NULL default '',
172
User varchar(16) binary NOT NULL default '',
173
PRIMARY KEY (Host,User)
176
ALTER TABLE t1 DISABLE KEYS;
177
LOCK TABLES t1 WRITE;
178
INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty');
180
ALTER TABLE t1 ENABLE KEYS;
186
155
# Test with two keys
158
CREATE TEMPORARY TABLE t1 (
190
159
Host varchar(16) binary NOT NULL default '',
191
160
User varchar(16) binary NOT NULL default '',
192
161
PRIMARY KEY (Host,User),
196
165
ALTER TABLE t1 DISABLE KEYS;
197
166
SHOW INDEX FROM t1;
198
LOCK TABLES t1 WRITE;
199
167
INSERT INTO t1 VALUES ('localhost','root'),('localhost','');
200
168
SHOW INDEX FROM t1;
201
169
ALTER TABLE t1 ENABLE KEYS;
202
170
SHOW INDEX FROM t1;
206
# Test RENAME with LOCK TABLES
207
LOCK TABLES t1 WRITE;
208
174
ALTER TABLE t1 RENAME t2;
210
175
select * from t2;
217
Host varchar(16) binary NOT NULL default '',
218
User varchar(16) binary NOT NULL default '',
219
PRIMARY KEY (Host,User),
223
LOCK TABLES t1 WRITE;
224
ALTER TABLE t1 DISABLE KEYS;
229
179
# BUG#4717 - check for valid table names
231
181
create table t1 (a int);
249
199
# The following is also part of bug #6236 (CREATE TABLE didn't properly count
250
200
# not null columns for primary keys)
252
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;
253
insert into t1 (a) values(1);
254
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
202
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;
203
insert into t1 (a,b,c,d,e,f,g,h,i) values(1,1,1,1,1,1,1,1,1);
204
--replace_column 3 X 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
255
205
show table status like 't1';
256
206
alter table t1 modify a int;
257
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
207
--replace_column 3 X 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
258
208
show table status like 't1';
260
create 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;
210
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;
261
211
insert into t1 (a) values(1);
262
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
212
--replace_column 3 X 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
263
213
show table status like 't1';
653
606
--echo End of 5.0 tests
656
# Extended test coverage for ALTER TABLE behaviour under LOCK TABLES
657
# It should be consistent across all platforms and for all engines
658
# (Before 5.1 this was not true as behavior was different between
659
# Unix/Windows and transactional/non-transactional tables).
660
# See also innodb_mysql.test
663
drop table if exists t1, t2, t3;
665
create table t1 (i int);
666
create table t3 (j int);
667
insert into t1 values ();
668
insert into t3 values ();
669
# Table which is altered under LOCK TABLES it should stay in list of locked
670
# tables and be available after alter takes place unless ALTER contains RENAME
671
# clause. We should see the new definition of table, of course.
672
lock table t1 write, t3 read;
673
# Example of so-called 'fast' ALTER TABLE
674
alter table t1 modify i int default 1;
675
insert into t1 values ();
677
# And now full-blown ALTER TABLE
678
alter table t1 change i c char(10) default "Two";
679
insert into t1 values ();
681
# If table is renamed then it should be removed from the list
682
# of locked tables. 'Fast' ALTER TABLE with RENAME clause:
683
alter table t1 modify c char(10) default "Three", rename to t2;
684
--error ER_TABLE_NOT_LOCKED
686
--error ER_TABLE_NOT_LOCKED
690
insert into t2 values ();
692
lock table t2 write, t3 read;
693
# Full ALTER TABLE with RENAME
694
alter table t2 change c vc varchar(100) default "Four", rename to t1;
695
--error ER_TABLE_NOT_LOCKED
697
--error ER_TABLE_NOT_LOCKED
701
insert into t1 values ();
707
609
# Bug#18775 - Temporary table from alter table visible to other threads
709
611
# Check if special characters work and duplicates are detected.
723
625
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
724
626
--error ER_TABLE_EXISTS_ERROR
725
627
ALTER TABLE `tt+1` RENAME `tt+2`;
628
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
726
629
SHOW CREATE TABLE `tt+1`;
630
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
727
631
SHOW CREATE TABLE `tt+2`;
728
632
DROP TABLE `tt+1`, `tt+2`;
751
655
INSERT INTO `#sql2` VALUES (1);
752
656
INSERT INTO `@0023sql1` VALUES (2);
657
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
753
658
SHOW CREATE TABLE `#sql2`;
659
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
754
660
SHOW CREATE TABLE `@0023sql1`;
755
661
DROP TABLE `#sql2`, `@0023sql1`;
758
665
# Bug #22369: Alter table rename combined with other alterations causes lost tables
760
667
# This problem happens if the data change is compatible.