~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/t/alter_table.test

Removed/replaced a couple DBUG calls

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null,
15
15
col6 int not null, to_be_deleted int);
16
16
insert into t1 values (2,4,3,5,"PENDING",1,7);
17
 
SELECT * FROM t1;
18
 
 
19
 
--error 1714
20
17
alter table t1
21
18
add column col4_5 varchar(20) not null after col4,
22
19
add column col7 varchar(30) not null after col5,
23
 
add column col8 datetime not null default '1000-01-01 00:00:00', drop column to_be_deleted,
24
 
change column col2 fourth varchar(30) not null after col3,
25
 
modify column col6 int not null first;
26
 
 
27
 
alter table t1
28
 
add column col4_5 varchar(20) DEFAULT "added" not null after col4,
29
 
add column col7 varchar(30) DEFAULT "added" not null after col5,
30
 
add column col8 datetime not null default '1000-01-01 00:00:00',
31
 
drop column to_be_deleted,
32
 
change column col2 fourth varchar(30) not null after col3,
33
 
modify column col6 int not null first;
34
 
 
 
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;
35
23
select * from t1;
36
24
drop table t1;
37
25
 
38
 
create table t1 (bandID INT NOT NULL PRIMARY KEY, payoutID int NOT NULL);
 
26
create table t1 (bandID MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, payoutID SMALLINT UNSIGNED NOT NULL);
39
27
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
40
 
alter table t1 add column new_col int;
 
28
alter table t1 add column new_col int, order by payoutid,bandid;
41
29
select * from t1;
42
 
alter table t1;
 
30
alter table t1 order by bandid,payoutid;
43
31
select * from t1;
44
32
drop table t1;
45
33
 
46
34
# Check that pack_keys and dynamic length rows are not forced. 
47
35
 
48
36
CREATE TABLE t1 (
49
 
GROUP_ID int DEFAULT '0' NOT NULL,
50
 
LANG_ID int DEFAULT '0' NOT NULL,
 
37
GROUP_ID int(10) unsigned DEFAULT '0' NOT NULL,
 
38
LANG_ID smallint(5) unsigned DEFAULT '0' NOT NULL,
51
39
NAME varchar(80) DEFAULT '' NOT NULL,
52
40
PRIMARY KEY (GROUP_ID,LANG_ID),
53
41
KEY NAME (NAME));
54
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
 
42
#show table status like "t1";
55
43
ALTER TABLE t1 CHANGE NAME NAME CHAR(80) not null;
56
44
--replace_column 8 #
57
 
show COLUMNS FROM t1;
 
45
SHOW FULL COLUMNS FROM t1;
58
46
DROP TABLE t1;
59
47
 
60
48
#
67
55
select * from t1;
68
56
drop table t1;
69
57
 
70
 
CREATE TEMPORARY TABLE t1 (
71
 
  id int NOT NULL default '0',
72
 
  category_id int NOT NULL default '0',
73
 
  type_id int NOT NULL default '0',
 
58
CREATE TABLE t1 (
 
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',
74
62
  body text NOT NULL,
75
 
  user_id int NOT NULL default '0',
 
63
  user_id int(11) unsigned NOT NULL default '0',
76
64
  status enum('new','old') NOT NULL default 'new',
77
65
  PRIMARY KEY (id)
78
66
) ENGINE=MyISAM;
81
69
DROP TABLE t1;
82
70
 
83
71
#
 
72
# The following combination found a hang-bug in MyISAM
 
73
#
 
74
 
 
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");
 
77
LOCK TABLES t1 WRITE;
 
78
ALTER TABLE t1 ADD Column new_col int not null;
 
79
UNLOCK TABLES;
 
80
OPTIMIZE TABLE t1;
 
81
DROP TABLE t1;
 
82
 
 
83
#
84
84
# Drop and add an auto_increment column
85
85
#
86
86
 
87
 
create table t1 (i int not null auto_increment primary key);
 
87
create table t1 (i int unsigned not null auto_increment primary key);
88
88
insert into t1 values (null),(null),(null),(null);
89
 
alter table t1 drop i,add i int not null auto_increment, drop primary key, add primary key (i);
 
89
alter table t1 drop i,add i int unsigned not null auto_increment, drop primary key, add primary key (i);
90
90
select * from t1;
91
91
drop table t1;
92
92
 
117
117
                key (n2, n3, n4, n1),
118
118
                key (n3, n4, n1, n2),
119
119
                key (n4, n1, n2, n3) );
120
 
alter table t1;
 
120
alter table t1 disable keys;
121
121
show keys from t1;
122
122
#let $1=10000;
123
 
set autocommit=0;
124
 
begin;
125
123
let $1=10;
126
124
while ($1)
127
125
{
128
126
 eval insert into t1 values($1,RAND()*1000,RAND()*1000,RAND());
129
127
 dec $1;
130
128
}
131
 
commit;
132
 
set autocommit=1;
133
129
alter table t1 enable keys;
134
130
show keys from t1;
135
131
drop table t1;
138
134
# Alter table and rename
139
135
#
140
136
 
141
 
create table t1 (i int not null auto_increment primary key);
 
137
create table t1 (i int unsigned not null auto_increment primary key);
142
138
alter table t1 rename t2;
143
139
alter table t2 rename t1, add c char(10) comment "no comment";
144
140
show columns from t1;
148
144
 
149
145
create table t1 (a int, b int);
150
146
let $1=100;
151
 
set autocommit=0;
152
 
begin;
153
147
while ($1)
154
148
{
155
149
 eval insert into t1 values(1,$1), (2,$1), (3, $1);
156
150
 dec $1;
157
151
}
158
 
commit;
159
 
set autocommit=1;
160
152
alter table t1 add unique (a,b), add key (b);
161
153
show keys from t1;
162
154
analyze table t1;
164
156
drop table t1;
165
157
 
166
158
#
 
159
# Test ALTER TABLE ENABLE/DISABLE keys when things are locked
 
160
#
 
161
 
 
162
CREATE TABLE t1 (
 
163
  Host varchar(16) binary NOT NULL default '',
 
164
  User varchar(16) binary NOT NULL default '',
 
165
  PRIMARY KEY  (Host,User)
 
166
) ENGINE=MyISAM;
 
167
 
 
168
ALTER TABLE t1 DISABLE KEYS;
 
169
LOCK TABLES t1 WRITE;
 
170
INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty');
 
171
SHOW INDEX FROM t1;
 
172
ALTER TABLE t1 ENABLE KEYS;
 
173
UNLOCK TABLES;
 
174
CHECK TABLES t1;
 
175
DROP TABLE t1;
 
176
 
 
177
#
167
178
# Test with two keys
168
179
#
169
180
 
170
 
CREATE TEMPORARY TABLE t1 (
171
 
  Host varchar(16) NOT NULL default '',
172
 
  User varchar(16) NOT NULL default '',
 
181
CREATE TABLE t1 (
 
182
  Host varchar(16) binary NOT NULL default '',
 
183
  User varchar(16) binary NOT NULL default '',
173
184
  PRIMARY KEY  (Host,User),
174
185
  KEY  (Host)
175
186
) ENGINE=MyISAM;
176
187
 
177
188
ALTER TABLE t1 DISABLE KEYS;
178
 
#SHOW INDEX FROM t1;
 
189
SHOW INDEX FROM t1;
 
190
LOCK TABLES t1 WRITE;
179
191
INSERT INTO t1 VALUES ('localhost','root'),('localhost','');
180
 
#SHOW INDEX FROM t1;
 
192
SHOW INDEX FROM t1;
181
193
ALTER TABLE t1 ENABLE KEYS;
182
 
#SHOW INDEX FROM t1;
 
194
SHOW INDEX FROM t1;
 
195
UNLOCK TABLES;
183
196
CHECK TABLES t1;
184
197
 
185
 
# Test RENAME
 
198
# Test RENAME with LOCK TABLES
 
199
LOCK TABLES t1 WRITE;
186
200
ALTER TABLE t1 RENAME t2;
 
201
UNLOCK TABLES;
187
202
select * from t2;
188
203
DROP TABLE t2;
189
204
 
190
205
#
 
206
# Test disable keys with locking
 
207
#
 
208
CREATE TABLE t1 (
 
209
  Host varchar(16) binary NOT NULL default '',
 
210
  User varchar(16) binary NOT NULL default '',
 
211
  PRIMARY KEY  (Host,User),
 
212
  KEY  (Host)
 
213
) ENGINE=MyISAM;
 
214
 
 
215
LOCK TABLES t1 WRITE;
 
216
ALTER TABLE t1 DISABLE KEYS;
 
217
SHOW INDEX FROM t1;
 
218
DROP TABLE t1;
 
219
 
 
220
#
191
221
# BUG#4717 - check for valid table names
192
222
#
193
223
create table t1 (a int);
201
231
# BUG#6236 - ALTER TABLE MODIFY should set implicit NOT NULL on PK columns
202
232
#
203
233
drop table if exists t1;
204
 
create TEMPORARY table t1 ( a varchar(10) not null primary key ) engine=myisam;
 
234
create table t1 ( a varchar(10) not null primary key ) engine=myisam;
205
235
flush tables;
206
236
alter table t1 modify a varchar(10);
207
237
flush tables;
211
241
# The following is also part of bug #6236 (CREATE TABLE didn't properly count
212
242
# not null columns for primary keys)
213
243
 
214
 
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;
215
 
insert into t1 (a,b,c,d,e,f,g,h,i) values(1,1,1,1,1,1,1,1,1);
216
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
 
244
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;
 
245
insert into t1 (a) values(1);
 
246
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
217
247
show table status like 't1';
218
248
alter table t1 modify a int;
219
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
 
249
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
220
250
show table status like 't1';
221
251
drop table t1;
222
 
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;
 
252
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;
223
253
insert into t1 (a) values(1);
224
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
 
254
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
225
255
show table status like 't1';
226
256
drop table t1;
227
257
 
228
258
#
 
259
# Test that data get converted when character set is changed
 
260
# Test that data doesn't get converted when src or dst is BINARY/BLOB
 
261
#
 
262
set names koi8r;
 
263
create table t1 (a char(10) character set koi8r);
 
264
insert into t1 values ('����');
 
265
select a,hex(a) from t1;
 
266
alter table t1 change a a char(10) character set cp1251;
 
267
select a,hex(a) from t1;
 
268
alter table t1 change a a binary(4);
 
269
select a,hex(a) from t1;
 
270
alter table t1 change a a char(10) character set cp1251;
 
271
select a,hex(a) from t1;
 
272
alter table t1 change a a char(10) character set koi8r;
 
273
select a,hex(a) from t1;
 
274
alter table t1 change a a varchar(10) character set cp1251;
 
275
select a,hex(a) from t1;
 
276
alter table t1 change a a char(10) character set koi8r;
 
277
select a,hex(a) from t1;
 
278
alter table t1 change a a text character set cp1251;
 
279
select a,hex(a) from t1;
 
280
alter table t1 change a a char(10) character set koi8r;
 
281
select a,hex(a) from t1;
 
282
delete from t1;
 
283
 
 
284
#
 
285
# Test ALTER TABLE .. CHARACTER SET ..
 
286
#
 
287
show create table t1;
 
288
alter table t1 DEFAULT CHARACTER SET latin1;
 
289
show create table t1;
 
290
alter table t1 CONVERT TO CHARACTER SET latin1;
 
291
show create table t1;
 
292
alter table t1 DEFAULT CHARACTER SET cp1251;
 
293
show create table t1;
 
294
 
 
295
drop table t1;
 
296
 
 
297
#
 
298
# Bug#2821
 
299
# Test that table CHARACTER SET does not affect blobs
 
300
#
 
301
create table t1 (myblob longblob,mytext longtext) 
 
302
default charset latin1 collate latin1_general_cs;
 
303
show create table t1;
 
304
alter table t1 character set latin2;
 
305
show create table t1;
 
306
drop table t1;
 
307
 
 
308
#
229
309
# Bug 2361 (Don't drop UNIQUE with DROP PRIMARY KEY)
230
310
#
231
311
 
232
312
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE);
233
313
ALTER TABLE t1 DROP PRIMARY KEY;
234
 
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
235
314
SHOW CREATE TABLE t1;
236
315
--error ER_CANT_DROP_FIELD_OR_KEY
237
316
ALTER TABLE t1 DROP PRIMARY KEY;
249
328
# BUG 12207 alter table ... discard table space on MyISAM table causes ERROR 2013 (HY000)
250
329
#
251
330
# Some platforms (Mac OS X, Windows) will send the error message using small letters.
252
 
CREATE TEMPORARY TABLE T12207(a int) ENGINE=MYISAM;
 
331
CREATE TABLE T12207(a int) ENGINE=MYISAM;
253
332
--replace_result t12207 T12207
254
333
--error ER_ILLEGAL_HA
255
334
ALTER TABLE T12207 DISCARD TABLESPACE;
256
335
DROP TABLE T12207;
257
336
 
258
337
#
 
338
# Bug #6479  ALTER TABLE ... changing charset fails for TEXT columns
 
339
#
 
340
# The column's character set was changed but the actual data was not
 
341
# modified. In other words, the values were reinterpreted
 
342
# as UTF8 instead of being converted.
 
343
create table t1 (a text) character set koi8r;
 
344
insert into t1 values (_koi8r'����');
 
345
select hex(a) from t1;
 
346
alter table t1 convert to character set cp1251;
 
347
select hex(a) from t1;
 
348
drop table t1;
 
349
 
 
350
#
259
351
# Test for bug #7884 "Able to add invalid unique index on TIMESTAMP prefix"
260
352
# MySQL should not think that packed field with non-zero decimals is
261
353
# geometry field and allow to create prefix index which is
278
370
create table t1 (a int, key(a));
279
371
show indexes from t1;
280
372
--echo "this used not to disable the index"
281
 
alter table t1 modify a int;
282
 
show indexes from t1;
283
 
 
284
 
alter table t1 enable keys;
285
 
show indexes from t1;
286
 
 
287
 
alter table t1 modify a bigint;
288
 
show indexes from t1;
289
 
 
290
 
alter table t1 enable keys;
291
 
show indexes from t1;
292
 
 
293
 
alter table t1 add b char(10);
294
 
show indexes from t1;
295
 
 
296
 
alter table t1 add c decimal(10,2);
 
373
alter table t1 modify a int, disable keys;
 
374
show indexes from t1;
 
375
 
 
376
alter table t1 enable keys;
 
377
show indexes from t1;
 
378
 
 
379
alter table t1 modify a bigint, disable keys;
 
380
show indexes from t1;
 
381
 
 
382
alter table t1 enable keys;
 
383
show indexes from t1;
 
384
 
 
385
alter table t1 add b char(10), disable keys;
 
386
show indexes from t1;
 
387
 
 
388
alter table t1 add c decimal(10,2), enable keys;
297
389
show indexes from t1;
298
390
 
299
391
--echo "this however did"
300
 
alter table t1;
 
392
alter table t1 disable keys;
301
393
show indexes from t1;
302
394
 
303
395
desc t1;
311
403
--echo "Now will test with one unique index"
312
404
create table t1(a int, b char(10), unique(a));
313
405
show indexes from t1;
314
 
alter table t1;
 
406
alter table t1 disable keys;
315
407
show indexes from t1;
316
408
alter table t1 enable keys;
317
409
 
318
410
--echo "If no copy on noop change, this won't touch the data file"
319
411
--echo "Unique index, no change"
320
 
alter table t1 modify a int;
 
412
alter table t1 modify a int, disable keys;
321
413
show indexes from t1;
322
414
 
323
415
--echo "Change the type implying data copy"
324
416
--echo "Unique index, no change"
325
 
alter table t1 modify a bigint;
 
417
alter table t1 modify a bigint, disable keys;
326
418
show indexes from t1;
327
419
 
328
420
alter table t1 modify a bigint;
336
428
--echo "Now will test with one unique and one non-unique index"
337
429
create table t1(a int, b char(10), unique(a), key(b));
338
430
show indexes from t1;
339
 
alter table t1;
 
431
alter table t1 disable keys;
340
432
show indexes from t1;
341
433
alter table t1 enable keys;
342
434
 
343
435
 
344
436
--echo "If no copy on noop change, this won't touch the data file"
345
437
--echo "The non-unique index will be disabled"
346
 
alter table t1 modify a int;
 
438
alter table t1 modify a int, disable keys;
347
439
show indexes from t1;
348
440
alter table t1 enable keys;
349
441
show indexes from t1;
350
442
 
351
443
--echo "Change the type implying data copy"
352
444
--echo "The non-unique index will be disabled"
353
 
alter table t1 modify a bigint;
 
445
alter table t1 modify a bigint, disable keys;
354
446
show indexes from t1;
355
447
 
356
448
--echo "Change again the type, but leave the indexes as_is"
395
487
drop table t1;
396
488
 
397
489
#
398
 
# BUG#23404 - ROW_FORMAT=COMPACT option is lost is an index is added to the
 
490
# BUG#23404 - ROW_FORMAT=FIXED option is lost is an index is added to the
399
491
# table
400
492
#
401
 
CREATE TABLE t1(a INT) ROW_FORMAT=COMPACT;
 
493
CREATE TABLE t1(a INT) ROW_FORMAT=FIXED;
402
494
CREATE INDEX i1 ON t1(a);
403
 
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
404
495
SHOW CREATE TABLE t1;
405
496
DROP INDEX i1 ON t1;
406
 
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
407
497
SHOW CREATE TABLE t1;
408
498
DROP TABLE t1;
409
499
 
482
572
alter table table_24562 order by (section + 12);
483
573
--error ER_PARSE_ERROR
484
574
alter table table_24562 order by length(title);
 
575
--error ER_PARSE_ERROR
 
576
alter table table_24562 order by (select 12 from dual);
485
577
 
486
578
--error ER_BAD_FIELD_ERROR
487
579
alter table table_24562 order by no_such_col;
494
586
# Bug #14693 (ALTER SET DEFAULT doesn't work)
495
587
#
496
588
 
497
 
create table t1 (mycol int not null);
 
589
create table t1 (mycol int(10) not null);
498
590
alter table t1 alter column mycol set default 0;
499
591
desc t1;
500
592
drop table t1;
503
595
# Bug#25262 Auto Increment lost when changing Engine type
504
596
#
505
597
 
506
 
create TEMPORARY table t1(id int primary key auto_increment) engine=MEMORY;
 
598
create table t1(id int(8) primary key auto_increment) engine=heap;
507
599
 
508
600
insert into t1 values (null);
509
601
insert into t1 values (null);
520
612
insert into t1 values (null);
521
613
select * from t1;
522
614
 
523
 
# Alter to MEMORY again
524
 
alter table t1 engine = MEMORY;
 
615
# Alter to heap again
 
616
alter table t1 engine = heap;
525
617
insert into t1 values (null);
526
618
select * from t1;
527
619
 
528
620
drop table t1;
529
621
 
530
 
##
531
 
## Bug#27507: Wrong DATETIME value was allowed by ALTER TABLE in the
532
 
##            NO_ZERO_DATE mode.
533
 
##
534
 
#create table t1(f1 int);
535
 
#alter table t1 add column f2 datetime not null, add column f21 date not null;
536
 
#insert into t1 values(1,'2000-01-01','2000-01-01');
537
 
#--error ER_TRUNCATED_WRONG_VALUE
538
 
#alter table t1 add column f3 datetime not null;
539
 
#--error ER_TRUNCATED_WRONG_VALUE
540
 
#alter table t1 add column f3 date not null;
541
 
#--error ER_TRUNCATED_WRONG_VALUE
542
 
#alter table t1 add column f4 datetime not null default '2002-02-02',
543
 
#  add column f41 date not null;
544
 
#alter table t1 add column f4 datetime not null default '2002-02-02',
545
 
#  add column f41 date not null default '2002-02-02';
546
 
#select * from t1;
547
 
#drop table t1;
 
622
#
 
623
# Bug#27507: Wrong DATETIME value was allowed by ALTER TABLE in the
 
624
#            NO_ZERO_DATE mode.
 
625
#
 
626
create table t1(f1 int);
 
627
alter table t1 add column f2 datetime not null, add column f21 date not null;
 
628
insert into t1 values(1,'2000-01-01','2000-01-01');
 
629
--error 1292
 
630
alter table t1 add column f3 datetime not null;
 
631
--error 1292
 
632
alter table t1 add column f3 date not null;
 
633
--error 1292
 
634
alter table t1 add column f4 datetime not null default '2002-02-02',
 
635
  add column f41 date not null;
 
636
alter table t1 add column f4 datetime not null default '2002-02-02',
 
637
  add column f41 date not null default '2002-02-02';
 
638
select * from t1;
 
639
drop table t1;
 
640
set sql_mode= @orig_sql_mode;
548
641
 
549
642
#
550
643
# Some additional tests for new, faster alter table.  Note that most of the
578
671
# without # prefix is not allowed for TEXT columns, while index
579
672
# is defined with prefix.
580
673
581
 
create TEMPORARY table t1 (t varchar(255) default null, key t (t(80))) engine=myisam;
 
674
create table t1 (t varchar(255) default null, key t (t(80)))
 
675
engine=myisam default charset=latin1;
582
676
alter table t1 change t t text;
583
677
drop table t1;
584
678
 
585
679
#
 
680
# Bug #26794: Adding an index with a prefix on a SPATIAL type breaks ALTER
 
681
# TABLE
 
682
#
 
683
CREATE TABLE t1 (a varchar(500));
 
684
 
 
685
ALTER TABLE t1 ADD b GEOMETRY NOT NULL, ADD SPATIAL INDEX(b);
 
686
SHOW CREATE TABLE t1;
 
687
ALTER TABLE t1 ADD KEY(b(50));
 
688
SHOW CREATE TABLE t1;
 
689
 
 
690
ALTER TABLE t1 ADD c POINT;
 
691
SHOW CREATE TABLE t1;
 
692
 
 
693
--error ER_WRONG_SUB_KEY
 
694
CREATE TABLE t2 (a INT, KEY (a(20)));
 
695
 
 
696
ALTER TABLE t1 ADD d INT;
 
697
--error ER_WRONG_SUB_KEY
 
698
ALTER TABLE t1 ADD KEY (d(20));
 
699
 
 
700
# the 5.1 part of the test
 
701
--error ER_WRONG_SUB_KEY
 
702
ALTER TABLE t1 ADD e GEOMETRY NOT NULL, ADD SPATIAL KEY (e(30));
 
703
 
 
704
DROP TABLE t1;
 
705
 
 
706
#
586
707
# Bug#18038  MySQL server corrupts binary columns data
587
708
#
588
709
 
589
 
CREATE TABLE t1 (s CHAR(8));
 
710
CREATE TABLE t1 (s CHAR(8) BINARY);
590
711
INSERT INTO t1 VALUES ('test');
591
712
SELECT LENGTH(s) FROM t1;
592
 
ALTER TABLE t1 MODIFY s CHAR(10);
 
713
ALTER TABLE t1 MODIFY s CHAR(10) BINARY;
593
714
SELECT LENGTH(s) FROM t1;
594
715
DROP TABLE t1;
595
716
 
596
 
CREATE TABLE t1 (s varbinary(8));
 
717
CREATE TABLE t1 (s BINARY(8));
597
718
INSERT INTO t1 VALUES ('test');
598
719
SELECT LENGTH(s) FROM t1;
599
720
SELECT HEX(s) FROM t1;
600
 
ALTER TABLE t1 MODIFY s varbinary(10);
 
721
ALTER TABLE t1 MODIFY s BINARY(10);
601
722
SELECT HEX(s) FROM t1;
602
723
SELECT LENGTH(s) FROM t1;
603
724
DROP TABLE t1;
618
739
--echo End of 5.0 tests
619
740
 
620
741
#
 
742
# Extended test coverage for ALTER TABLE behaviour under LOCK TABLES
 
743
# It should be consistent across all platforms and for all engines
 
744
# (Before 5.1 this was not true as behavior was different between 
 
745
# Unix/Windows and transactional/non-transactional tables).
 
746
# See also innodb_mysql.test
 
747
#
 
748
--disable_warnings
 
749
drop table if exists t1, t2, t3;
 
750
--enable_warnings
 
751
create table t1 (i int);
 
752
create table t3 (j int);
 
753
insert into t1 values ();
 
754
insert into t3 values ();
 
755
# Table which is altered under LOCK TABLES it should stay in list of locked
 
756
# tables and be available after alter takes place unless ALTER contains RENAME
 
757
# clause. We should see the new definition of table, of course.
 
758
lock table t1 write, t3 read;
 
759
# Example of so-called 'fast' ALTER TABLE
 
760
alter table t1 modify i int default 1;
 
761
insert into t1 values ();
 
762
select * from t1;
 
763
# And now full-blown ALTER TABLE
 
764
alter table t1 change i c char(10) default "Two";
 
765
insert into t1 values ();
 
766
select * from t1;
 
767
# If table is renamed then it should be removed from the list
 
768
# of locked tables. 'Fast' ALTER TABLE with RENAME clause:
 
769
alter table t1 modify c char(10) default "Three", rename to t2;
 
770
--error ER_TABLE_NOT_LOCKED
 
771
select * from t1;
 
772
--error ER_TABLE_NOT_LOCKED
 
773
select * from t2;
 
774
select * from t3;
 
775
unlock tables;
 
776
insert into t2 values ();
 
777
select * from t2;
 
778
lock table t2 write, t3 read;
 
779
# Full ALTER TABLE with RENAME
 
780
alter table t2 change c vc varchar(100) default "Four", rename to t1;
 
781
--error ER_TABLE_NOT_LOCKED
 
782
select * from t1;
 
783
--error ER_TABLE_NOT_LOCKED
 
784
select * from t2;
 
785
select * from t3;
 
786
unlock tables;
 
787
insert into t1 values ();
 
788
select * from t1;
 
789
drop tables t1, t3;
 
790
 
 
791
 
 
792
#
621
793
# Bug#18775 - Temporary table from alter table visible to other threads
622
794
#
623
795
# Check if special characters work and duplicates are detected.
637
809
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
638
810
--error ER_TABLE_EXISTS_ERROR
639
811
ALTER TABLE  `tt+1` RENAME `tt+2`;
640
 
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
641
812
SHOW CREATE TABLE `tt+1`;
642
 
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
643
813
SHOW CREATE TABLE `tt+2`;
644
814
DROP TABLE   `tt+1`, `tt+2`;
645
 
##
646
 
## Check if special characters as in tmp_file_prefix work.
647
 
#CREATE TABLE `#sql1` (c1 INT);
648
 
#CREATE TABLE `@0023sql2` (c1 INT);
649
 
#SHOW TABLES;
650
 
#RENAME TABLE `#sql1`     TO `@0023sql1`;
651
 
#RENAME TABLE `@0023sql2` TO `#sql2`;
652
 
#SHOW TABLES;
653
 
#ALTER TABLE `@0023sql1`  RENAME `#sql-1`;
654
 
#ALTER TABLE `#sql2`      RENAME `@0023sql-2`;
655
 
#SHOW TABLES;
656
 
#INSERT INTO `#sql-1`     VALUES (1);
657
 
#INSERT INTO `@0023sql-2` VALUES (2);
658
 
#DROP TABLE `#sql-1`, `@0023sql-2`;
 
815
#
 
816
# Check if special characters as in tmp_file_prefix work.
 
817
CREATE TABLE `#sql1` (c1 INT);
 
818
CREATE TABLE `@0023sql2` (c1 INT);
 
819
SHOW TABLES;
 
820
RENAME TABLE `#sql1`     TO `@0023sql1`;
 
821
RENAME TABLE `@0023sql2` TO `#sql2`;
 
822
SHOW TABLES;
 
823
ALTER TABLE `@0023sql1`  RENAME `#sql-1`;
 
824
ALTER TABLE `#sql2`      RENAME `@0023sql-2`;
 
825
SHOW TABLES;
 
826
INSERT INTO `#sql-1`     VALUES (1);
 
827
INSERT INTO `@0023sql-2` VALUES (2);
 
828
DROP TABLE `#sql-1`, `@0023sql-2`;
659
829
#
660
830
# Same for temporary tables though these names do not become file names.
661
831
CREATE TEMPORARY TABLE `#sql1` (c1 INT);
666
836
SHOW TABLES;
667
837
INSERT INTO `#sql2`      VALUES (1);
668
838
INSERT INTO `@0023sql1`  VALUES (2);
669
 
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
670
839
SHOW CREATE TABLE `#sql2`;
671
 
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
672
840
SHOW CREATE TABLE `@0023sql1`;
673
841
DROP TABLE `#sql2`, `@0023sql1`;
674
842
 
675
843
#
676
 
#
677
844
# Bug #22369: Alter table rename combined with other alterations causes lost tables
678
845
#
679
846
# This problem happens if the data change is compatible.
684
851
DROP TABLE IF EXISTS t2;
685
852
--enable_warnings
686
853
CREATE TABLE t1 (
687
 
  int_field INTEGER NOT NULL,
 
854
  int_field INTEGER UNSIGNED NOT NULL,
688
855
  char_field CHAR(10),
689
856
  INDEX(`int_field`)
690
857
);
695
862
 
696
863
INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet"); 
697
864
--echo "Non-copy data change - new frm, but old data and index files"
698
 
ALTER TABLE t1 CHANGE int_field unsigned_int_field INTEGER NOT NULL, RENAME t2;
 
865
ALTER TABLE t1
 
866
  CHANGE int_field unsigned_int_field INTEGER UNSIGNED NOT NULL,
 
867
  RENAME t2;
699
868
 
700
869
--error ER_NO_SUCH_TABLE
701
870
SELECT * FROM t1 ORDER BY int_field;
702
871
SELECT * FROM t2 ORDER BY unsigned_int_field;
703
872
DESCRIBE t2;
704
873
DESCRIBE t2;
705
 
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT NOT NULL;
 
874
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT UNSIGNED NOT NULL;
706
875
DESCRIBE t2;
707
876
 
708
877
DROP TABLE t2;
718
887
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2;
719
888
SELECT * FROM t1;
720
889
DROP TABLE t1;
 
890
 
 
891
#
 
892
# BUG#29957 - alter_table.test fails
 
893
#
 
894
create table t1 (c char(10) default "Two");
 
895
lock table t1 write;
 
896
insert into t1 values ();
 
897
alter table t1 modify c char(10) default "Three";
 
898
unlock tables;
 
899
select * from t1;
 
900
check table t1;
 
901
drop table t1;