~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Test of alter table
3
#
4
--disable_warnings
5
drop table if exists t1,t2;
6
drop database if exists mysqltest;
7
--enable_warnings
8
9
create table t1 (
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);
17
alter table t1
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;
23
select * from t1;
24
drop table t1;
25
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
26
create table t1 (bandID INT NOT NULL PRIMARY KEY, payoutID int NOT NULL);
1 by brian
clean slate
27
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
201 by Brian Aker
Convert default engine to Innodb
28
alter table t1 add column new_col int;
1 by brian
clean slate
29
select * from t1;
201 by Brian Aker
Convert default engine to Innodb
30
alter table t1;
1 by brian
clean slate
31
select * from t1;
32
drop table t1;
33
34
# Check that pack_keys and dynamic length rows are not forced. 
35
36
CREATE TABLE t1 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
37
GROUP_ID int DEFAULT '0' NOT NULL,
38
LANG_ID int DEFAULT '0' NOT NULL,
1 by brian
clean slate
39
NAME varchar(80) DEFAULT '' NOT NULL,
40
PRIMARY KEY (GROUP_ID,LANG_ID),
41
KEY NAME (NAME));
42
#show table status like "t1";
43
ALTER TABLE t1 CHANGE NAME NAME CHAR(80) not null;
44
--replace_column 8 #
45
SHOW FULL COLUMNS FROM t1;
46
DROP TABLE t1;
47
48
#
49
# Test of ALTER TABLE ... ORDER BY
50
#
51
52
create table t1 (n int);
53
insert into t1 values(9),(3),(12),(10);
54
alter table t1 order by n;
55
select * from t1;
56
drop table t1;
57
58
CREATE TABLE t1 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
59
  id int NOT NULL default '0',
60
  category_id int NOT NULL default '0',
61
  type_id int NOT NULL default '0',
1 by brian
clean slate
62
  body text NOT NULL,
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
63
  user_id int NOT NULL default '0',
1 by brian
clean slate
64
  status enum('new','old') NOT NULL default 'new',
65
  PRIMARY KEY (id)
66
) ENGINE=MyISAM;
67
68
ALTER TABLE t1 ORDER BY t1.id, t1.status, t1.type_id, t1.user_id, t1.body;
69
DROP TABLE t1;
70
71
#
72
# The following combination found a hang-bug in MyISAM
73
#
74
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
75
CREATE TABLE t1 (AnamneseId int NOT NULL auto_increment,B BLOB,PRIMARY KEY (AnamneseId)) engine=myisam;
1 by brian
clean slate
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
# Drop and add an auto_increment column
85
#
86
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
87
create table t1 (i int not null auto_increment primary key);
1 by brian
clean slate
88
insert into t1 values (null),(null),(null),(null);
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
89
alter table t1 drop i,add i int not null auto_increment, drop primary key, add primary key (i);
1 by brian
clean slate
90
select * from t1;
91
drop table t1;
92
93
#
94
# Bug #2628: 'alter table t1 rename mysqltest.t1' silently drops mysqltest.t1 
95
# if it exists
96
#
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");
102
select * from t1;
103
select * from mysqltest.t1;
104
--error ER_TABLE_EXISTS_ERROR
105
alter table t1 rename mysqltest.t1;
106
select * from t1;
107
select * from mysqltest.t1;
108
drop table t1;
109
drop database mysqltest;
110
111
#
112
# ALTER TABLE ... ENABLE/DISABLE KEYS
113
114
create table t1 (n1 int not null, n2 int, n3 int, n4 float,
115
                unique(n1),
116
                key (n1, n2, n3, n4),
117
                key (n2, n3, n4, n1),
118
                key (n3, n4, n1, n2),
119
                key (n4, n1, n2, n3) );
201 by Brian Aker
Convert default engine to Innodb
120
alter table t1;
1 by brian
clean slate
121
show keys from t1;
122
#let $1=10000;
206.1.1 by Stewart Smith
cut 'make test' time in half.
123
set autocommit=0;
124
begin;
1 by brian
clean slate
125
let $1=10;
126
while ($1)
127
{
128
 eval insert into t1 values($1,RAND()*1000,RAND()*1000,RAND());
129
 dec $1;
130
}
206.1.1 by Stewart Smith
cut 'make test' time in half.
131
commit;
132
set autocommit=1;
1 by brian
clean slate
133
alter table t1 enable keys;
134
show keys from t1;
135
drop table t1;
136
137
#
138
# Alter table and rename
139
#
140
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
141
create table t1 (i int not null auto_increment primary key);
1 by brian
clean slate
142
alter table t1 rename t2;
143
alter table t2 rename t1, add c char(10) comment "no comment";
144
show columns from t1;
145
drop table t1;
146
147
# implicit analyze
148
149
create table t1 (a int, b int);
150
let $1=100;
206.1.1 by Stewart Smith
cut 'make test' time in half.
151
set autocommit=0;
152
begin;
1 by brian
clean slate
153
while ($1)
154
{
155
 eval insert into t1 values(1,$1), (2,$1), (3, $1);
156
 dec $1;
157
}
206.1.1 by Stewart Smith
cut 'make test' time in half.
158
commit;
159
set autocommit=1;
1 by brian
clean slate
160
alter table t1 add unique (a,b), add key (b);
161
show keys from t1;
162
analyze table t1;
163
show keys from t1;
164
drop table t1;
165
166
#
167
# Test ALTER TABLE ENABLE/DISABLE keys when things are locked
168
#
169
170
CREATE TABLE t1 (
171
  Host varchar(16) binary NOT NULL default '',
172
  User varchar(16) binary NOT NULL default '',
173
  PRIMARY KEY  (Host,User)
174
) ENGINE=MyISAM;
175
176
ALTER TABLE t1 DISABLE KEYS;
177
LOCK TABLES t1 WRITE;
178
INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty');
179
SHOW INDEX FROM t1;
180
ALTER TABLE t1 ENABLE KEYS;
181
UNLOCK TABLES;
182
CHECK TABLES t1;
183
DROP TABLE t1;
184
185
#
186
# Test with two keys
187
#
188
189
CREATE TABLE t1 (
190
  Host varchar(16) binary NOT NULL default '',
191
  User varchar(16) binary NOT NULL default '',
192
  PRIMARY KEY  (Host,User),
193
  KEY  (Host)
194
) ENGINE=MyISAM;
195
196
ALTER TABLE t1 DISABLE KEYS;
197
SHOW INDEX FROM t1;
198
LOCK TABLES t1 WRITE;
199
INSERT INTO t1 VALUES ('localhost','root'),('localhost','');
200
SHOW INDEX FROM t1;
201
ALTER TABLE t1 ENABLE KEYS;
202
SHOW INDEX FROM t1;
203
UNLOCK TABLES;
204
CHECK TABLES t1;
205
206
# Test RENAME with LOCK TABLES
207
LOCK TABLES t1 WRITE;
208
ALTER TABLE t1 RENAME t2;
209
UNLOCK TABLES;
210
select * from t2;
211
DROP TABLE t2;
212
213
#
201 by Brian Aker
Convert default engine to Innodb
214
# Test with locking
1 by brian
clean slate
215
#
216
CREATE TABLE t1 (
217
  Host varchar(16) binary NOT NULL default '',
218
  User varchar(16) binary NOT NULL default '',
219
  PRIMARY KEY  (Host,User),
220
  KEY  (Host)
221
) ENGINE=MyISAM;
222
223
LOCK TABLES t1 WRITE;
224
ALTER TABLE t1 DISABLE KEYS;
225
SHOW INDEX FROM t1;
226
DROP TABLE t1;
227
228
#
229
# BUG#4717 - check for valid table names
230
#
231
create table t1 (a int);
232
--error ER_WRONG_TABLE_NAME
233
alter table t1 rename to ``;
234
--error ER_WRONG_TABLE_NAME
235
rename table t1 to ``;
236
drop table t1;
237
238
#
239
# BUG#6236 - ALTER TABLE MODIFY should set implicit NOT NULL on PK columns
240
#
241
drop table if exists t1;
242
create table t1 ( a varchar(10) not null primary key ) engine=myisam;
243
flush tables;
244
alter table t1 modify a varchar(10);
245
flush tables;
246
alter table t1 modify a varchar(10) not null;
247
drop table if exists t1;
248
249
# The following is also part of bug #6236 (CREATE TABLE didn't properly count
250
# not null columns for primary keys)
251
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;
896.3.6 by Stewart Smith
Read Fields out of proto instead of FRM.
253
insert into t1 (a,b,c,d,e,f,g,h,i) values(1,1,1,1,1,1,1,1,1);
590.1.4 by Stewart Smith
remove frm_version from TABLE_SHARE
254
--replace_column 3 X 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
1 by brian
clean slate
255
show table status like 't1';
256
alter table t1 modify a int;
590.1.4 by Stewart Smith
remove frm_version from TABLE_SHARE
257
--replace_column 3 X 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
1 by brian
clean slate
258
show table status like 't1';
259
drop table 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;
261
insert into t1 (a) values(1);
590.1.4 by Stewart Smith
remove frm_version from TABLE_SHARE
262
--replace_column 3 X 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
1 by brian
clean slate
263
show table status like 't1';
264
drop table t1;
265
266
#
267
# Bug 2361 (Don't drop UNIQUE with DROP PRIMARY KEY)
268
#
269
270
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE);
271
ALTER TABLE t1 DROP PRIMARY KEY;
942.3.1 by Vladimir Kolesnikov
test generalizations
272
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
273
SHOW CREATE TABLE t1;
274
--error ER_CANT_DROP_FIELD_OR_KEY
275
ALTER TABLE t1 DROP PRIMARY KEY;
276
DROP TABLE t1;
277
278
# BUG#3899
279
create table t1 (a int, b int, key(a));
280
insert into t1 values (1,1), (2,2);
281
--error ER_CANT_DROP_FIELD_OR_KEY
282
alter table t1 drop key no_such_key;
283
alter table t1 drop key a;
284
drop table t1;
285
286
#
287
# BUG 12207 alter table ... discard table space on MyISAM table causes ERROR 2013 (HY000)
288
#
289
# Some platforms (Mac OS X, Windows) will send the error message using small letters.
290
CREATE TABLE T12207(a int) ENGINE=MYISAM;
291
--replace_result t12207 T12207
292
--error ER_ILLEGAL_HA
293
ALTER TABLE T12207 DISCARD TABLESPACE;
294
DROP TABLE T12207;
295
296
#
297
# Test for bug #7884 "Able to add invalid unique index on TIMESTAMP prefix"
298
# MySQL should not think that packed field with non-zero decimals is
299
# geometry field and allow to create prefix index which is
300
# shorter than packed field length.
301
#
302
create table t1 ( a timestamp );
303
--error ER_WRONG_SUB_KEY
304
alter table t1 add unique ( a(1) );
305
drop table t1;
306
307
#
308
# Bug #24395: ALTER TABLE DISABLE KEYS doesn't work when modifying the table
309
#
310
# This problem happens if the data change is compatible.
311
# Changing to the same type is compatible for example.
312
#
313
--disable_warnings
314
drop table if exists t1;
315
--enable_warnings
316
create table t1 (a int, key(a));
317
show indexes from t1;
318
--echo "this used not to disable the index"
201 by Brian Aker
Convert default engine to Innodb
319
alter table t1 modify a int;
320
show indexes from t1;
321
322
alter table t1 enable keys;
323
show indexes from t1;
324
325
alter table t1 modify a bigint;
326
show indexes from t1;
327
328
alter table t1 enable keys;
329
show indexes from t1;
330
331
alter table t1 add b char(10);
332
show indexes from t1;
333
334
alter table t1 add c decimal(10,2);
1 by brian
clean slate
335
show indexes from t1;
336
337
--echo "this however did"
201 by Brian Aker
Convert default engine to Innodb
338
alter table t1;
1 by brian
clean slate
339
show indexes from t1;
340
341
desc t1;
342
343
alter table t1 add d decimal(15,5);
344
--echo "The key should still be disabled"
345
show indexes from t1;
346
347
drop table t1;
348
349
--echo "Now will test with one unique index"
350
create table t1(a int, b char(10), unique(a));
351
show indexes from t1;
201 by Brian Aker
Convert default engine to Innodb
352
alter table t1;
1 by brian
clean slate
353
show indexes from t1;
354
alter table t1 enable keys;
355
356
--echo "If no copy on noop change, this won't touch the data file"
357
--echo "Unique index, no change"
201 by Brian Aker
Convert default engine to Innodb
358
alter table t1 modify a int;
1 by brian
clean slate
359
show indexes from t1;
360
361
--echo "Change the type implying data copy"
362
--echo "Unique index, no change"
201 by Brian Aker
Convert default engine to Innodb
363
alter table t1 modify a bigint;
1 by brian
clean slate
364
show indexes from t1;
365
366
alter table t1 modify a bigint;
367
show indexes from t1;
368
369
alter table t1 modify a int;
370
show indexes from t1;
371
372
drop table t1;
373
374
--echo "Now will test with one unique and one non-unique index"
375
create table t1(a int, b char(10), unique(a), key(b));
376
show indexes from t1;
201 by Brian Aker
Convert default engine to Innodb
377
alter table t1;
1 by brian
clean slate
378
show indexes from t1;
379
alter table t1 enable keys;
380
381
382
--echo "If no copy on noop change, this won't touch the data file"
383
--echo "The non-unique index will be disabled"
201 by Brian Aker
Convert default engine to Innodb
384
alter table t1 modify a int;
1 by brian
clean slate
385
show indexes from t1;
386
alter table t1 enable keys;
387
show indexes from t1;
388
389
--echo "Change the type implying data copy"
390
--echo "The non-unique index will be disabled"
201 by Brian Aker
Convert default engine to Innodb
391
alter table t1 modify a bigint;
1 by brian
clean slate
392
show indexes from t1;
393
394
--echo "Change again the type, but leave the indexes as_is"
395
alter table t1 modify a int;
396
show indexes from t1;
397
--echo "Try the same. When data is no copied on similar tables, this is noop"
398
alter table t1 modify a int;
399
show indexes from t1;
400
401
drop table t1;
402
403
404
#
405
# Bug#11493 - Alter table rename to default database does not work without
406
#             db name qualifying
407
#
408
create database mysqltest;
409
create table t1 (c1 int);
410
# Move table to other database.
411
alter table t1 rename mysqltest.t1;
412
# Assure that it has moved.
413
--error ER_BAD_TABLE_ERROR
414
drop table t1;
415
# Move table back.
416
alter table mysqltest.t1 rename t1;
417
# Assure that it is back.
418
drop table t1;
419
# Now test for correct message if no database is selected.
420
# Create t1 in 'test'.
421
create table t1 (c1 int);
422
# Change to other db.
423
use mysqltest;
424
# Drop the current db. This de-selects any db.
425
drop database mysqltest;
426
# Now test for correct message.
427
--error ER_NO_DB_ERROR
428
alter table test.t1 rename t1;
429
# Check that explicit qualifying works even with no selected db.
430
alter table test.t1 rename test.t1;
431
# Go back to standard 'test' db.
432
use test;
433
drop table t1;
434
435
#
436
# BUG#23404 - ROW_FORMAT=FIXED option is lost is an index is added to the
437
# table
438
#
439
CREATE TABLE t1(a INT) ROW_FORMAT=FIXED;
440
CREATE INDEX i1 ON t1(a);
942.3.1 by Vladimir Kolesnikov
test generalizations
441
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
442
SHOW CREATE TABLE t1;
443
DROP INDEX i1 ON t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
444
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
445
SHOW CREATE TABLE t1;
446
DROP TABLE t1;
447
448
#
449
# Bug#24219 - ALTER TABLE ... RENAME TO ... , DISABLE KEYS leads to crash
450
#
451
--disable_warnings
452
DROP TABLE IF EXISTS bug24219;
453
DROP TABLE IF EXISTS bug24219_2;
454
--enable_warnings
455
456
CREATE TABLE bug24219 (a INT, INDEX(a));
457
458
SHOW INDEX FROM bug24219;
459
460
ALTER TABLE bug24219 RENAME TO bug24219_2, DISABLE KEYS;
461
462
SHOW INDEX FROM bug24219_2;
463
464
DROP TABLE bug24219_2;
465
466
#
467
# Bug#24562 (ALTER TABLE ... ORDER BY ... with complex expression asserts)
468
#
469
470
--disable_warnings
471
drop table if exists table_24562;
472
--enable_warnings
473
474
create table table_24562(
475
  section int,
476
  subsection int,
477
  title varchar(50));
478
479
insert into table_24562 values
480
(1, 0, "Introduction"),
481
(1, 1, "Authors"),
482
(1, 2, "Acknowledgements"),
483
(2, 0, "Basics"),
484
(2, 1, "Syntax"),
485
(2, 2, "Client"),
486
(2, 3, "Server"),
487
(3, 0, "Intermediate"),
488
(3, 1, "Complex queries"),
489
(3, 2, "Stored Procedures"),
490
(3, 3, "Stored Functions"),
491
(4, 0, "Advanced"),
492
(4, 1, "Replication"),
493
(4, 2, "Load balancing"),
494
(4, 3, "High availability"),
495
(5, 0, "Conclusion");
496
497
select * from table_24562;
498
499
alter table table_24562 add column reviewer varchar(20),
500
order by title;
501
502
select * from table_24562;
503
504
update table_24562 set reviewer="Me" where section=2;
505
update table_24562 set reviewer="You" where section=3;
506
507
alter table table_24562
508
order by section ASC, subsection DESC;
509
510
select * from table_24562;
511
512
alter table table_24562
513
order by table_24562.subsection ASC, table_24562.section DESC;
514
515
select * from table_24562;
516
517
--error ER_PARSE_ERROR
518
alter table table_24562 order by 12;
519
--error ER_PARSE_ERROR
520
alter table table_24562 order by (section + 12);
521
--error ER_PARSE_ERROR
522
alter table table_24562 order by length(title);
523
524
--error ER_BAD_FIELD_ERROR
525
alter table table_24562 order by no_such_col;
526
527
drop table table_24562;
528
529
# End of 4.1 tests
530
531
#
532
# Bug #14693 (ALTER SET DEFAULT doesn't work)
533
#
534
223 by Brian Aker
Cleanup int() work.
535
create table t1 (mycol int not null);
1 by brian
clean slate
536
alter table t1 alter column mycol set default 0;
537
desc t1;
538
drop table t1;
539
540
#
541
# Bug#25262 Auto Increment lost when changing Engine type
542
#
543
223 by Brian Aker
Cleanup int() work.
544
create table t1(id int primary key auto_increment) engine=heap;
1 by brian
clean slate
545
546
insert into t1 values (null);
547
insert into t1 values (null);
548
549
select * from t1;
550
551
# Set auto increment to 50
552
alter table t1 auto_increment = 50;
553
554
# Alter to myisam
555
alter table t1 engine = myisam;
556
557
# This insert should get id 50
558
insert into t1 values (null);
559
select * from t1;
560
561
# Alter to heap again
562
alter table t1 engine = heap;
563
insert into t1 values (null);
564
select * from t1;
565
566
drop table t1;
567
186 by Brian Aker
Partial fix for alter table
568
##
569
## Bug#27507: Wrong DATETIME value was allowed by ALTER TABLE in the
570
##            NO_ZERO_DATE mode.
571
##
572
#create table t1(f1 int);
573
#alter table t1 add column f2 datetime not null, add column f21 date not null;
574
#insert into t1 values(1,'2000-01-01','2000-01-01');
575
#--error 1292
576
#alter table t1 add column f3 datetime not null;
577
#--error 1292
578
#alter table t1 add column f3 date not null;
579
#--error 1292
580
#alter table t1 add column f4 datetime not null default '2002-02-02',
581
#  add column f41 date not null;
582
#alter table t1 add column f4 datetime not null default '2002-02-02',
583
#  add column f41 date not null default '2002-02-02';
584
#select * from t1;
585
#drop table t1;
1 by brian
clean slate
586
587
#
588
# Some additional tests for new, faster alter table.  Note that most of the
589
# whole alter table code is being tested all around the test suite already.
590
#
591
592
create table t1 (v varchar(32));
593
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
594
select * from t1;
595
# Fast alter, no copy performed
596
alter table t1 change v v2 varchar(32);
597
select * from t1;
598
# Fast alter, no copy performed
599
alter table t1 change v2 v varchar(64);
600
select * from t1;
601
update t1 set v = 'lmn' where v = 'hij';
602
select * from t1;
603
# Regular alter table
604
alter table t1 add i int auto_increment not null primary key first;
605
select * from t1;
606
update t1 set i=5 where i=3;
607
select * from t1;
608
alter table t1 change i i bigint;
609
select * from t1;
610
alter table t1 add unique key (i, v);
611
select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
612
drop table t1;
613
614
#
615
# Bug#6073 "ALTER table minor glich": ALTER TABLE complains that an index
616
# without # prefix is not allowed for TEXT columns, while index
617
# is defined with prefix.
618
# 
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
619
create table t1 (t varchar(255) default null, key t (t(80))) engine=myisam;
1 by brian
clean slate
620
alter table t1 change t t text;
621
drop table t1;
622
623
#
624
# Bug#18038  MySQL server corrupts binary columns data
625
#
626
627
CREATE TABLE t1 (s CHAR(8) BINARY);
628
INSERT INTO t1 VALUES ('test');
629
SELECT LENGTH(s) FROM t1;
630
ALTER TABLE t1 MODIFY s CHAR(10) BINARY;
631
SELECT LENGTH(s) FROM t1;
632
DROP TABLE t1;
633
233 by Brian Aker
Fix to remove binary/nchar
634
CREATE TABLE t1 (s varbinary(8));
1 by brian
clean slate
635
INSERT INTO t1 VALUES ('test');
636
SELECT LENGTH(s) FROM t1;
637
SELECT HEX(s) FROM t1;
233 by Brian Aker
Fix to remove binary/nchar
638
ALTER TABLE t1 MODIFY s varbinary(10);
1 by brian
clean slate
639
SELECT HEX(s) FROM t1;
640
SELECT LENGTH(s) FROM t1;
641
DROP TABLE t1;
642
643
#
644
# Bug#19386: Multiple alter causes crashed table
645
# The trailing column would get corrupted data, or server could not even read
646
# it.
647
#
648
649
CREATE TABLE t1 (v VARCHAR(3), b INT);
650
INSERT INTO t1 VALUES ('abc', 5);
651
SELECT * FROM t1;
652
ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4);
653
SELECT * FROM t1;
654
DROP TABLE t1;
655
656
--echo End of 5.0 tests
657
658
#
659
# Extended test coverage for ALTER TABLE behaviour under LOCK TABLES
660
# It should be consistent across all platforms and for all engines
661
# (Before 5.1 this was not true as behavior was different between 
662
# Unix/Windows and transactional/non-transactional tables).
663
# See also innodb_mysql.test
664
#
665
--disable_warnings
666
drop table if exists t1, t2, t3;
667
--enable_warnings
668
create table t1 (i int);
669
create table t3 (j int);
670
insert into t1 values ();
671
insert into t3 values ();
672
# Table which is altered under LOCK TABLES it should stay in list of locked
673
# tables and be available after alter takes place unless ALTER contains RENAME
674
# clause. We should see the new definition of table, of course.
675
lock table t1 write, t3 read;
676
# Example of so-called 'fast' ALTER TABLE
677
alter table t1 modify i int default 1;
678
insert into t1 values ();
679
select * from t1;
680
# And now full-blown ALTER TABLE
681
alter table t1 change i c char(10) default "Two";
682
insert into t1 values ();
683
select * from t1;
684
# If table is renamed then it should be removed from the list
685
# of locked tables. 'Fast' ALTER TABLE with RENAME clause:
686
alter table t1 modify c char(10) default "Three", rename to t2;
687
--error ER_TABLE_NOT_LOCKED
688
select * from t1;
689
--error ER_TABLE_NOT_LOCKED
690
select * from t2;
691
select * from t3;
692
unlock tables;
693
insert into t2 values ();
694
select * from t2;
695
lock table t2 write, t3 read;
696
# Full ALTER TABLE with RENAME
697
alter table t2 change c vc varchar(100) default "Four", rename to t1;
698
--error ER_TABLE_NOT_LOCKED
699
select * from t1;
700
--error ER_TABLE_NOT_LOCKED
701
select * from t2;
702
select * from t3;
703
unlock tables;
704
insert into t1 values ();
705
select * from t1;
706
drop tables t1, t3;
707
708
709
#
710
# Bug#18775 - Temporary table from alter table visible to other threads
711
#
712
# Check if special characters work and duplicates are detected.
713
--disable_warnings
714
DROP TABLE IF EXISTS `t+1`, `t+2`;
715
--enable_warnings
716
CREATE TABLE `t+1` (c1 INT);
717
ALTER TABLE  `t+1` RENAME `t+2`;
718
CREATE TABLE `t+1` (c1 INT);
719
--error ER_TABLE_EXISTS_ERROR
720
ALTER TABLE  `t+1` RENAME `t+2`;
721
DROP TABLE   `t+1`, `t+2`;
722
#
723
# Same for temporary tables though these names do not become file names.
724
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
725
ALTER TABLE  `tt+1` RENAME `tt+2`;
726
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
727
--error ER_TABLE_EXISTS_ERROR
728
ALTER TABLE  `tt+1` RENAME `tt+2`;
942.3.1 by Vladimir Kolesnikov
test generalizations
729
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
730
SHOW CREATE TABLE `tt+1`;
942.3.1 by Vladimir Kolesnikov
test generalizations
731
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
732
SHOW CREATE TABLE `tt+2`;
733
DROP TABLE   `tt+1`, `tt+2`;
186 by Brian Aker
Partial fix for alter table
734
##
735
## Check if special characters as in tmp_file_prefix work.
736
#CREATE TABLE `#sql1` (c1 INT);
737
#CREATE TABLE `@0023sql2` (c1 INT);
738
#SHOW TABLES;
739
#RENAME TABLE `#sql1`     TO `@0023sql1`;
740
#RENAME TABLE `@0023sql2` TO `#sql2`;
741
#SHOW TABLES;
742
#ALTER TABLE `@0023sql1`  RENAME `#sql-1`;
743
#ALTER TABLE `#sql2`      RENAME `@0023sql-2`;
744
#SHOW TABLES;
745
#INSERT INTO `#sql-1`     VALUES (1);
746
#INSERT INTO `@0023sql-2` VALUES (2);
747
#DROP TABLE `#sql-1`, `@0023sql-2`;
1 by brian
clean slate
748
#
749
# Same for temporary tables though these names do not become file names.
750
CREATE TEMPORARY TABLE `#sql1` (c1 INT);
751
CREATE TEMPORARY TABLE `@0023sql2` (c1 INT);
752
SHOW TABLES;
753
ALTER TABLE `#sql1`      RENAME `@0023sql1`;
754
ALTER TABLE `@0023sql2`  RENAME `#sql2`;
755
SHOW TABLES;
756
INSERT INTO `#sql2`      VALUES (1);
757
INSERT INTO `@0023sql1`  VALUES (2);
942.3.1 by Vladimir Kolesnikov
test generalizations
758
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
759
SHOW CREATE TABLE `#sql2`;
942.3.1 by Vladimir Kolesnikov
test generalizations
760
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
761
SHOW CREATE TABLE `@0023sql1`;
762
DROP TABLE `#sql2`, `@0023sql1`;
763
764
#
942.3.1 by Vladimir Kolesnikov
test generalizations
765
#
1 by brian
clean slate
766
# Bug #22369: Alter table rename combined with other alterations causes lost tables
767
#
768
# This problem happens if the data change is compatible.
769
# Changing to the same type is compatible for example.
770
#
771
--disable_warnings
772
DROP TABLE IF EXISTS t1;
773
DROP TABLE IF EXISTS t2;
774
--enable_warnings
775
CREATE TABLE t1 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
776
  int_field INTEGER NOT NULL,
1 by brian
clean slate
777
  char_field CHAR(10),
778
  INDEX(`int_field`)
779
);
780
781
DESCRIBE t1;
782
783
SHOW INDEXES FROM t1;
784
785
INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet"); 
786
--echo "Non-copy data change - new frm, but old data and index files"
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
787
ALTER TABLE t1 CHANGE int_field unsigned_int_field INTEGER NOT NULL, RENAME t2;
1 by brian
clean slate
788
789
--error ER_NO_SUCH_TABLE
790
SELECT * FROM t1 ORDER BY int_field;
791
SELECT * FROM t2 ORDER BY unsigned_int_field;
792
DESCRIBE t2;
793
DESCRIBE t2;
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
794
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT NOT NULL;
1 by brian
clean slate
795
DESCRIBE t2;
796
797
DROP TABLE t2;
798
799
#
800
# Bug#28427: Columns were renamed instead of moving by ALTER TABLE.
801
#
802
CREATE TABLE t1 (f1 INT, f2 INT, f3 INT);
803
INSERT INTO t1 VALUES (1, 2, NULL);
804
SELECT * FROM t1;
805
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f1;
806
SELECT * FROM t1;
807
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2;
808
SELECT * FROM t1;
809
DROP TABLE t1;
810
811
#
812
# BUG#29957 - alter_table.test fails
813
#
814
create table t1 (c char(10) default "Two");
815
lock table t1 write;
816
insert into t1 values ();
817
alter table t1 modify c char(10) default "Three";
818
unlock tables;
819
select * from t1;
820
check table t1;
821
drop table t1;