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 |
||
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; |
|
29 |
select * from t1; |
|
30 |
alter table t1 order by bandid,payoutid; |
|
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 ( |
|
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), |
|
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 ( |
|
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', |
|
62 |
body text NOT NULL, |
|
63 |
user_id int(11) unsigned NOT NULL default '0', |
|
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 |
||
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 |
# Drop and add an auto_increment column
|
|
85 |
#
|
|
86 |
||
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); |
|
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) ); |
|
120 |
alter table t1 disable keys; |
|
121 |
show keys from t1; |
|
122 |
#let $1=10000;
|
|
123 |
let $1=10; |
|
124 |
while ($1) |
|
125 |
{
|
|
126 |
eval insert into t1 values($1,RAND()*1000,RAND()*1000,RAND()); |
|
127 |
dec $1; |
|
128 |
}
|
|
129 |
alter table t1 enable keys; |
|
130 |
show keys from t1; |
|
131 |
drop table t1; |
|
132 |
||
133 |
#
|
|
134 |
# Alter table and rename
|
|
135 |
#
|
|
136 |
||
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; |
|
141 |
drop table t1; |
|
142 |
||
143 |
# implicit analyze
|
|
144 |
||
145 |
create table t1 (a int, b int); |
|
146 |
let $1=100; |
|
147 |
while ($1) |
|
148 |
{
|
|
149 |
eval insert into t1 values(1,$1), (2,$1), (3, $1); |
|
150 |
dec $1; |
|
151 |
}
|
|
152 |
alter table t1 add unique (a,b), add key (b); |
|
153 |
show keys from t1; |
|
154 |
analyze table t1; |
|
155 |
show keys from t1; |
|
156 |
drop table t1; |
|
157 |
||
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 |
#
|
|
178 |
# Test with two keys
|
|
179 |
#
|
|
180 |
||
181 |
CREATE TABLE t1 ( |
|
182 |
Host varchar(16) binary NOT NULL default '', |
|
183 |
User varchar(16) binary NOT NULL default '', |
|
184 |
PRIMARY KEY (Host,User), |
|
185 |
KEY (Host) |
|
186 |
) ENGINE=MyISAM; |
|
187 |
||
188 |
ALTER TABLE t1 DISABLE KEYS; |
|
189 |
SHOW INDEX FROM t1; |
|
190 |
LOCK TABLES t1 WRITE; |
|
191 |
INSERT INTO t1 VALUES ('localhost','root'),('localhost',''); |
|
192 |
SHOW INDEX FROM t1; |
|
193 |
ALTER TABLE t1 ENABLE KEYS; |
|
194 |
SHOW INDEX FROM t1; |
|
195 |
UNLOCK TABLES; |
|
196 |
CHECK TABLES t1; |
|
197 |
||
198 |
# Test RENAME with LOCK TABLES
|
|
199 |
LOCK TABLES t1 WRITE; |
|
200 |
ALTER TABLE t1 RENAME t2; |
|
201 |
UNLOCK TABLES; |
|
202 |
select * from t2; |
|
203 |
DROP TABLE t2; |
|
204 |
||
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 |
#
|
|
221 |
# BUG#4717 - check for valid table names
|
|
222 |
#
|
|
223 |
create table t1 (a int); |
|
224 |
--error ER_WRONG_TABLE_NAME |
|
225 |
alter table t1 rename to ``; |
|
226 |
--error ER_WRONG_TABLE_NAME |
|
227 |
rename table t1 to ``; |
|
228 |
drop table t1; |
|
229 |
||
230 |
#
|
|
231 |
# BUG#6236 - ALTER TABLE MODIFY should set implicit NOT NULL on PK columns
|
|
232 |
#
|
|
233 |
drop table if exists t1; |
|
234 |
create table t1 ( a varchar(10) not null primary key ) engine=myisam; |
|
235 |
flush tables; |
|
236 |
alter table t1 modify a varchar(10); |
|
237 |
flush tables; |
|
238 |
alter table t1 modify a varchar(10) not null; |
|
239 |
drop table if exists t1; |
|
240 |
||
241 |
# The following is also part of bug #6236 (CREATE TABLE didn't properly count
|
|
242 |
# not null columns for primary keys)
|
|
243 |
||
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 |
|
247 |
show table status like 't1'; |
|
248 |
alter table t1 modify a int; |
|
249 |
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X |
|
250 |
show table status like 't1'; |
|
251 |
drop table t1; |
|
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; |
|
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 |
|
255 |
show table status like 't1'; |
|
256 |
drop table t1; |
|
257 |
||
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 |
#
|
|
309 |
# Bug 2361 (Don't drop UNIQUE with DROP PRIMARY KEY)
|
|
310 |
#
|
|
311 |
||
312 |
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE); |
|
313 |
ALTER TABLE t1 DROP PRIMARY KEY; |
|
314 |
SHOW CREATE TABLE t1; |
|
315 |
--error ER_CANT_DROP_FIELD_OR_KEY |
|
316 |
ALTER TABLE t1 DROP PRIMARY KEY; |
|
317 |
DROP TABLE t1; |
|
318 |
||
319 |
# BUG#3899
|
|
320 |
create table t1 (a int, b int, key(a)); |
|
321 |
insert into t1 values (1,1), (2,2); |
|
322 |
--error ER_CANT_DROP_FIELD_OR_KEY |
|
323 |
alter table t1 drop key no_such_key; |
|
324 |
alter table t1 drop key a; |
|
325 |
drop table t1; |
|
326 |
||
327 |
#
|
|
328 |
# BUG 12207 alter table ... discard table space on MyISAM table causes ERROR 2013 (HY000)
|
|
329 |
#
|
|
330 |
# Some platforms (Mac OS X, Windows) will send the error message using small letters.
|
|
331 |
CREATE TABLE T12207(a int) ENGINE=MYISAM; |
|
332 |
--replace_result t12207 T12207 |
|
333 |
--error ER_ILLEGAL_HA |
|
334 |
ALTER TABLE T12207 DISCARD TABLESPACE; |
|
335 |
DROP TABLE T12207; |
|
336 |
||
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 |
#
|
|
351 |
# Test for bug #7884 "Able to add invalid unique index on TIMESTAMP prefix"
|
|
352 |
# MySQL should not think that packed field with non-zero decimals is
|
|
353 |
# geometry field and allow to create prefix index which is
|
|
354 |
# shorter than packed field length.
|
|
355 |
#
|
|
356 |
create table t1 ( a timestamp ); |
|
357 |
--error ER_WRONG_SUB_KEY |
|
358 |
alter table t1 add unique ( a(1) ); |
|
359 |
drop table t1; |
|
360 |
||
361 |
#
|
|
362 |
# Bug #24395: ALTER TABLE DISABLE KEYS doesn't work when modifying the table
|
|
363 |
#
|
|
364 |
# This problem happens if the data change is compatible.
|
|
365 |
# Changing to the same type is compatible for example.
|
|
366 |
#
|
|
367 |
--disable_warnings |
|
368 |
drop table if exists t1; |
|
369 |
--enable_warnings |
|
370 |
create table t1 (a int, key(a)); |
|
371 |
show indexes from t1; |
|
372 |
--echo "this used not to disable the index" |
|
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; |
|
389 |
show indexes from t1; |
|
390 |
||
391 |
--echo "this however did" |
|
392 |
alter table t1 disable keys; |
|
393 |
show indexes from t1; |
|
394 |
||
395 |
desc t1; |
|
396 |
||
397 |
alter table t1 add d decimal(15,5); |
|
398 |
--echo "The key should still be disabled" |
|
399 |
show indexes from t1; |
|
400 |
||
401 |
drop table t1; |
|
402 |
||
403 |
--echo "Now will test with one unique index" |
|
404 |
create table t1(a int, b char(10), unique(a)); |
|
405 |
show indexes from t1; |
|
406 |
alter table t1 disable keys; |
|
407 |
show indexes from t1; |
|
408 |
alter table t1 enable keys; |
|
409 |
||
410 |
--echo "If no copy on noop change, this won't touch the data file" |
|
411 |
--echo "Unique index, no change" |
|
412 |
alter table t1 modify a int, disable keys; |
|
413 |
show indexes from t1; |
|
414 |
||
415 |
--echo "Change the type implying data copy" |
|
416 |
--echo "Unique index, no change" |
|
417 |
alter table t1 modify a bigint, disable keys; |
|
418 |
show indexes from t1; |
|
419 |
||
420 |
alter table t1 modify a bigint; |
|
421 |
show indexes from t1; |
|
422 |
||
423 |
alter table t1 modify a int; |
|
424 |
show indexes from t1; |
|
425 |
||
426 |
drop table t1; |
|
427 |
||
428 |
--echo "Now will test with one unique and one non-unique index" |
|
429 |
create table t1(a int, b char(10), unique(a), key(b)); |
|
430 |
show indexes from t1; |
|
431 |
alter table t1 disable keys; |
|
432 |
show indexes from t1; |
|
433 |
alter table t1 enable keys; |
|
434 |
||
435 |
||
436 |
--echo "If no copy on noop change, this won't touch the data file" |
|
437 |
--echo "The non-unique index will be disabled" |
|
438 |
alter table t1 modify a int, disable keys; |
|
439 |
show indexes from t1; |
|
440 |
alter table t1 enable keys; |
|
441 |
show indexes from t1; |
|
442 |
||
443 |
--echo "Change the type implying data copy" |
|
444 |
--echo "The non-unique index will be disabled" |
|
445 |
alter table t1 modify a bigint, disable keys; |
|
446 |
show indexes from t1; |
|
447 |
||
448 |
--echo "Change again the type, but leave the indexes as_is" |
|
449 |
alter table t1 modify a int; |
|
450 |
show indexes from t1; |
|
451 |
--echo "Try the same. When data is no copied on similar tables, this is noop" |
|
452 |
alter table t1 modify a int; |
|
453 |
show indexes from t1; |
|
454 |
||
455 |
drop table t1; |
|
456 |
||
457 |
||
458 |
#
|
|
459 |
# Bug#11493 - Alter table rename to default database does not work without
|
|
460 |
# db name qualifying
|
|
461 |
#
|
|
462 |
create database mysqltest; |
|
463 |
create table t1 (c1 int); |
|
464 |
# Move table to other database.
|
|
465 |
alter table t1 rename mysqltest.t1; |
|
466 |
# Assure that it has moved.
|
|
467 |
--error ER_BAD_TABLE_ERROR |
|
468 |
drop table t1; |
|
469 |
# Move table back.
|
|
470 |
alter table mysqltest.t1 rename t1; |
|
471 |
# Assure that it is back.
|
|
472 |
drop table t1; |
|
473 |
# Now test for correct message if no database is selected.
|
|
474 |
# Create t1 in 'test'.
|
|
475 |
create table t1 (c1 int); |
|
476 |
# Change to other db.
|
|
477 |
use mysqltest; |
|
478 |
# Drop the current db. This de-selects any db.
|
|
479 |
drop database mysqltest; |
|
480 |
# Now test for correct message.
|
|
481 |
--error ER_NO_DB_ERROR |
|
482 |
alter table test.t1 rename t1; |
|
483 |
# Check that explicit qualifying works even with no selected db.
|
|
484 |
alter table test.t1 rename test.t1; |
|
485 |
# Go back to standard 'test' db.
|
|
486 |
use test; |
|
487 |
drop table t1; |
|
488 |
||
489 |
#
|
|
490 |
# BUG#23404 - ROW_FORMAT=FIXED option is lost is an index is added to the
|
|
491 |
# table
|
|
492 |
#
|
|
493 |
CREATE TABLE t1(a INT) ROW_FORMAT=FIXED; |
|
494 |
CREATE INDEX i1 ON t1(a); |
|
495 |
SHOW CREATE TABLE t1; |
|
496 |
DROP INDEX i1 ON t1; |
|
497 |
SHOW CREATE TABLE t1; |
|
498 |
DROP TABLE t1; |
|
499 |
||
500 |
#
|
|
501 |
# Bug#24219 - ALTER TABLE ... RENAME TO ... , DISABLE KEYS leads to crash
|
|
502 |
#
|
|
503 |
--disable_warnings |
|
504 |
DROP TABLE IF EXISTS bug24219; |
|
505 |
DROP TABLE IF EXISTS bug24219_2; |
|
506 |
--enable_warnings |
|
507 |
||
508 |
CREATE TABLE bug24219 (a INT, INDEX(a)); |
|
509 |
||
510 |
SHOW INDEX FROM bug24219; |
|
511 |
||
512 |
ALTER TABLE bug24219 RENAME TO bug24219_2, DISABLE KEYS; |
|
513 |
||
514 |
SHOW INDEX FROM bug24219_2; |
|
515 |
||
516 |
DROP TABLE bug24219_2; |
|
517 |
||
518 |
#
|
|
519 |
# Bug#24562 (ALTER TABLE ... ORDER BY ... with complex expression asserts)
|
|
520 |
#
|
|
521 |
||
522 |
--disable_warnings |
|
523 |
drop table if exists table_24562; |
|
524 |
--enable_warnings |
|
525 |
||
526 |
create table table_24562( |
|
527 |
section int, |
|
528 |
subsection int, |
|
529 |
title varchar(50)); |
|
530 |
||
531 |
insert into table_24562 values |
|
532 |
(1, 0, "Introduction"), |
|
533 |
(1, 1, "Authors"), |
|
534 |
(1, 2, "Acknowledgements"), |
|
535 |
(2, 0, "Basics"), |
|
536 |
(2, 1, "Syntax"), |
|
537 |
(2, 2, "Client"), |
|
538 |
(2, 3, "Server"), |
|
539 |
(3, 0, "Intermediate"), |
|
540 |
(3, 1, "Complex queries"), |
|
541 |
(3, 2, "Stored Procedures"), |
|
542 |
(3, 3, "Stored Functions"), |
|
543 |
(4, 0, "Advanced"), |
|
544 |
(4, 1, "Replication"), |
|
545 |
(4, 2, "Load balancing"), |
|
546 |
(4, 3, "High availability"), |
|
547 |
(5, 0, "Conclusion"); |
|
548 |
||
549 |
select * from table_24562; |
|
550 |
||
551 |
alter table table_24562 add column reviewer varchar(20), |
|
552 |
order by title; |
|
553 |
||
554 |
select * from table_24562; |
|
555 |
||
556 |
update table_24562 set reviewer="Me" where section=2; |
|
557 |
update table_24562 set reviewer="You" where section=3; |
|
558 |
||
559 |
alter table table_24562 |
|
560 |
order by section ASC, subsection DESC; |
|
561 |
||
562 |
select * from table_24562; |
|
563 |
||
564 |
alter table table_24562 |
|
565 |
order by table_24562.subsection ASC, table_24562.section DESC; |
|
566 |
||
567 |
select * from table_24562; |
|
568 |
||
569 |
--error ER_PARSE_ERROR |
|
570 |
alter table table_24562 order by 12; |
|
571 |
--error ER_PARSE_ERROR |
|
572 |
alter table table_24562 order by (section + 12); |
|
573 |
--error ER_PARSE_ERROR |
|
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); |
|
577 |
||
578 |
--error ER_BAD_FIELD_ERROR |
|
579 |
alter table table_24562 order by no_such_col; |
|
580 |
||
581 |
drop table table_24562; |
|
582 |
||
583 |
# End of 4.1 tests
|
|
584 |
||
585 |
#
|
|
586 |
# Bug #14693 (ALTER SET DEFAULT doesn't work)
|
|
587 |
#
|
|
588 |
||
589 |
create table t1 (mycol int(10) not null); |
|
590 |
alter table t1 alter column mycol set default 0; |
|
591 |
desc t1; |
|
592 |
drop table t1; |
|
593 |
||
594 |
#
|
|
595 |
# Bug#25262 Auto Increment lost when changing Engine type
|
|
596 |
#
|
|
597 |
||
598 |
create table t1(id int(8) primary key auto_increment) engine=heap; |
|
599 |
||
600 |
insert into t1 values (null); |
|
601 |
insert into t1 values (null); |
|
602 |
||
603 |
select * from t1; |
|
604 |
||
605 |
# Set auto increment to 50
|
|
606 |
alter table t1 auto_increment = 50; |
|
607 |
||
608 |
# Alter to myisam
|
|
609 |
alter table t1 engine = myisam; |
|
610 |
||
611 |
# This insert should get id 50
|
|
612 |
insert into t1 values (null); |
|
613 |
select * from t1; |
|
614 |
||
615 |
# Alter to heap again
|
|
616 |
alter table t1 engine = heap; |
|
617 |
insert into t1 values (null); |
|
618 |
select * from t1; |
|
619 |
||
620 |
drop table t1; |
|
621 |
||
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; |
|
641 |
||
642 |
#
|
|
643 |
# Some additional tests for new, faster alter table. Note that most of the
|
|
644 |
# whole alter table code is being tested all around the test suite already.
|
|
645 |
#
|
|
646 |
||
647 |
create table t1 (v varchar(32)); |
|
648 |
insert into t1 values ('def'),('abc'),('hij'),('3r4f'); |
|
649 |
select * from t1; |
|
650 |
# Fast alter, no copy performed
|
|
651 |
alter table t1 change v v2 varchar(32); |
|
652 |
select * from t1; |
|
653 |
# Fast alter, no copy performed
|
|
654 |
alter table t1 change v2 v varchar(64); |
|
655 |
select * from t1; |
|
656 |
update t1 set v = 'lmn' where v = 'hij'; |
|
657 |
select * from t1; |
|
658 |
# Regular alter table
|
|
659 |
alter table t1 add i int auto_increment not null primary key first; |
|
660 |
select * from t1; |
|
661 |
update t1 set i=5 where i=3; |
|
662 |
select * from t1; |
|
663 |
alter table t1 change i i bigint; |
|
664 |
select * from t1; |
|
665 |
alter table t1 add unique key (i, v); |
|
666 |
select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn'); |
|
667 |
drop table t1; |
|
668 |
||
669 |
#
|
|
670 |
# Bug#6073 "ALTER table minor glich": ALTER TABLE complains that an index
|
|
671 |
# without # prefix is not allowed for TEXT columns, while index
|
|
672 |
# is defined with prefix.
|
|
673 |
#
|
|
674 |
create table t1 (t varchar(255) default null, key t (t(80))) |
|
675 |
engine=myisam default charset=latin1; |
|
676 |
alter table t1 change t t text; |
|
677 |
drop table t1; |
|
678 |
||
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 |
#
|
|
707 |
# Bug#18038 MySQL server corrupts binary columns data
|
|
708 |
#
|
|
709 |
||
710 |
CREATE TABLE t1 (s CHAR(8) BINARY); |
|
711 |
INSERT INTO t1 VALUES ('test'); |
|
712 |
SELECT LENGTH(s) FROM t1; |
|
713 |
ALTER TABLE t1 MODIFY s CHAR(10) BINARY; |
|
714 |
SELECT LENGTH(s) FROM t1; |
|
715 |
DROP TABLE t1; |
|
716 |
||
717 |
CREATE TABLE t1 (s BINARY(8)); |
|
718 |
INSERT INTO t1 VALUES ('test'); |
|
719 |
SELECT LENGTH(s) FROM t1; |
|
720 |
SELECT HEX(s) FROM t1; |
|
721 |
ALTER TABLE t1 MODIFY s BINARY(10); |
|
722 |
SELECT HEX(s) FROM t1; |
|
723 |
SELECT LENGTH(s) FROM t1; |
|
724 |
DROP TABLE t1; |
|
725 |
||
726 |
#
|
|
727 |
# Bug#19386: Multiple alter causes crashed table
|
|
728 |
# The trailing column would get corrupted data, or server could not even read
|
|
729 |
# it.
|
|
730 |
#
|
|
731 |
||
732 |
CREATE TABLE t1 (v VARCHAR(3), b INT); |
|
733 |
INSERT INTO t1 VALUES ('abc', 5); |
|
734 |
SELECT * FROM t1; |
|
735 |
ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4); |
|
736 |
SELECT * FROM t1; |
|
737 |
DROP TABLE t1; |
|
738 |
||
739 |
--echo End of 5.0 tests |
|
740 |
||
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 |
#
|
|
793 |
# Bug#18775 - Temporary table from alter table visible to other threads
|
|
794 |
#
|
|
795 |
# Check if special characters work and duplicates are detected.
|
|
796 |
--disable_warnings |
|
797 |
DROP TABLE IF EXISTS `t+1`, `t+2`; |
|
798 |
--enable_warnings |
|
799 |
CREATE TABLE `t+1` (c1 INT); |
|
800 |
ALTER TABLE `t+1` RENAME `t+2`; |
|
801 |
CREATE TABLE `t+1` (c1 INT); |
|
802 |
--error ER_TABLE_EXISTS_ERROR |
|
803 |
ALTER TABLE `t+1` RENAME `t+2`; |
|
804 |
DROP TABLE `t+1`, `t+2`; |
|
805 |
#
|
|
806 |
# Same for temporary tables though these names do not become file names.
|
|
807 |
CREATE TEMPORARY TABLE `tt+1` (c1 INT); |
|
808 |
ALTER TABLE `tt+1` RENAME `tt+2`; |
|
809 |
CREATE TEMPORARY TABLE `tt+1` (c1 INT); |
|
810 |
--error ER_TABLE_EXISTS_ERROR |
|
811 |
ALTER TABLE `tt+1` RENAME `tt+2`; |
|
812 |
SHOW CREATE TABLE `tt+1`; |
|
813 |
SHOW CREATE TABLE `tt+2`; |
|
814 |
DROP TABLE `tt+1`, `tt+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`; |
|
829 |
#
|
|
830 |
# Same for temporary tables though these names do not become file names.
|
|
831 |
CREATE TEMPORARY TABLE `#sql1` (c1 INT); |
|
832 |
CREATE TEMPORARY TABLE `@0023sql2` (c1 INT); |
|
833 |
SHOW TABLES; |
|
834 |
ALTER TABLE `#sql1` RENAME `@0023sql1`; |
|
835 |
ALTER TABLE `@0023sql2` RENAME `#sql2`; |
|
836 |
SHOW TABLES; |
|
837 |
INSERT INTO `#sql2` VALUES (1); |
|
838 |
INSERT INTO `@0023sql1` VALUES (2); |
|
839 |
SHOW CREATE TABLE `#sql2`; |
|
840 |
SHOW CREATE TABLE `@0023sql1`; |
|
841 |
DROP TABLE `#sql2`, `@0023sql1`; |
|
842 |
||
843 |
#
|
|
844 |
# Bug #22369: Alter table rename combined with other alterations causes lost tables
|
|
845 |
#
|
|
846 |
# This problem happens if the data change is compatible.
|
|
847 |
# Changing to the same type is compatible for example.
|
|
848 |
#
|
|
849 |
--disable_warnings |
|
850 |
DROP TABLE IF EXISTS t1; |
|
851 |
DROP TABLE IF EXISTS t2; |
|
852 |
--enable_warnings |
|
853 |
CREATE TABLE t1 ( |
|
854 |
int_field INTEGER UNSIGNED NOT NULL, |
|
855 |
char_field CHAR(10), |
|
856 |
INDEX(`int_field`) |
|
857 |
);
|
|
858 |
||
859 |
DESCRIBE t1; |
|
860 |
||
861 |
SHOW INDEXES FROM t1; |
|
862 |
||
863 |
INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet"); |
|
864 |
--echo "Non-copy data change - new frm, but old data and index files" |
|
865 |
ALTER TABLE t1 |
|
866 |
CHANGE int_field unsigned_int_field INTEGER UNSIGNED NOT NULL, |
|
867 |
RENAME t2; |
|
868 |
||
869 |
--error ER_NO_SUCH_TABLE |
|
870 |
SELECT * FROM t1 ORDER BY int_field; |
|
871 |
SELECT * FROM t2 ORDER BY unsigned_int_field; |
|
872 |
DESCRIBE t2; |
|
873 |
DESCRIBE t2; |
|
874 |
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT UNSIGNED NOT NULL; |
|
875 |
DESCRIBE t2; |
|
876 |
||
877 |
DROP TABLE t2; |
|
878 |
||
879 |
#
|
|
880 |
# Bug#28427: Columns were renamed instead of moving by ALTER TABLE.
|
|
881 |
#
|
|
882 |
CREATE TABLE t1 (f1 INT, f2 INT, f3 INT); |
|
883 |
INSERT INTO t1 VALUES (1, 2, NULL); |
|
884 |
SELECT * FROM t1; |
|
885 |
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f1; |
|
886 |
SELECT * FROM t1; |
|
887 |
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2; |
|
888 |
SELECT * FROM t1; |
|
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; |