~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/alter_table.result

  • Committer: Jay Pipes
  • Date: 2008-07-17 18:48:58 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: jay@mysql.com-20080717184858-2mbouxl8xi41gcge
Removed DBUG from CSV and Blackhole storage engines

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
drop table if exists t1,t2;
2
 
drop database if exists mysqltest;
3
 
create table t1 (
4
 
col1 int not null auto_increment primary key,
5
 
col2 varchar(30) not null,
6
 
col3 varchar (20) not null,
7
 
col4 varchar(4) not null,
8
 
col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null,
9
 
col6 int not null, to_be_deleted int);
10
 
insert into t1 values (2,4,3,5,"PENDING",1,7);
11
 
SELECT * FROM t1;
12
 
col1    col2    col3    col4    col5    col6    to_be_deleted
13
 
2       4       3       5       PENDING 1       7
14
 
alter table t1
15
 
add column col4_5 varchar(20) not null after col4,
16
 
add column col7 varchar(30) not null after col5,
17
 
add column col8 datetime not null default '1000-01-01 00:00:00', drop column to_be_deleted,
18
 
change column col2 fourth varchar(30) not null after col3,
19
 
modify column col6 int not null first;
20
 
ERROR HY000: Either a DEFAULt value or NULL NULL description is required for a new column if table is not empty
21
 
alter table t1
22
 
add column col4_5 varchar(20) DEFAULT "added" not null after col4,
23
 
add column col7 varchar(30) DEFAULT "added" not null after col5,
24
 
add column col8 datetime not null default '1000-01-01 00:00:00',
25
 
drop column to_be_deleted,
26
 
change column col2 fourth varchar(30) not null after col3,
27
 
modify column col6 int not null first;
28
 
select * from t1;
29
 
col6    col1    col3    fourth  col4    col4_5  col5    col7    col8
30
 
1       2       3       4       5       added   PENDING added   1000-01-01 00:00:00
31
 
drop table t1;
32
 
create table t1 (bandID INT NOT NULL PRIMARY KEY, payoutID int NOT NULL);
33
 
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
34
 
alter table t1 add column new_col int;
35
 
select * from t1;
36
 
bandID  payoutID        new_col
37
 
1       6       NULL
38
 
2       6       NULL
39
 
3       4       NULL
40
 
4       9       NULL
41
 
5       10      NULL
42
 
6       1       NULL
43
 
7       12      NULL
44
 
8       12      NULL
45
 
alter table t1;
46
 
select * from t1;
47
 
bandID  payoutID        new_col
48
 
1       6       NULL
49
 
2       6       NULL
50
 
3       4       NULL
51
 
4       9       NULL
52
 
5       10      NULL
53
 
6       1       NULL
54
 
7       12      NULL
55
 
8       12      NULL
56
 
drop table t1;
57
 
CREATE TABLE t1 (
58
 
GROUP_ID int DEFAULT '0' NOT NULL,
59
 
LANG_ID int DEFAULT '0' NOT NULL,
60
 
NAME varchar(80) DEFAULT '' NOT NULL,
61
 
PRIMARY KEY (GROUP_ID,LANG_ID),
62
 
KEY NAME (NAME));
63
 
ALTER TABLE t1 CHANGE NAME NAME CHAR(80) not null;
64
 
show COLUMNS FROM t1;
65
 
Field   Type    Null    Default Default_is_NULL On_Update
66
 
GROUP_ID        INTEGER NO      0       NO      
67
 
LANG_ID INTEGER NO      0       NO      
68
 
NAME    VARCHAR NO              NO      
69
 
DROP TABLE t1;
70
 
create table t1 (n int);
71
 
insert into t1 values(9),(3),(12),(10);
72
 
alter table t1 order by n;
73
 
select * from t1;
74
 
n
75
 
3
76
 
9
77
 
10
78
 
12
79
 
drop table t1;
80
 
CREATE TEMPORARY TABLE t1 (
81
 
id int NOT NULL default '0',
82
 
category_id int NOT NULL default '0',
83
 
type_id int NOT NULL default '0',
84
 
body text NOT NULL,
85
 
user_id int NOT NULL default '0',
86
 
status enum('new','old') NOT NULL default 'new',
87
 
PRIMARY KEY (id)
88
 
) ENGINE=MyISAM;
89
 
ALTER TABLE t1 ORDER BY t1.id, t1.status, t1.type_id, t1.user_id, t1.body;
90
 
DROP TABLE t1;
91
 
create table t1 (i int not null auto_increment primary key);
92
 
insert into t1 values (null),(null),(null),(null);
93
 
alter table t1 drop i,add i int not null auto_increment, drop primary key, add primary key (i);
94
 
select * from t1;
95
 
i
96
 
1
97
 
2
98
 
3
99
 
4
100
 
drop table t1;
101
 
create table t1 (name char(15));
102
 
insert into t1 (name) values ("current");
103
 
create database mysqltest;
104
 
create table mysqltest.t1 (name char(15));
105
 
insert into mysqltest.t1 (name) values ("mysqltest");
106
 
select * from t1;
107
 
name
108
 
current
109
 
select * from mysqltest.t1;
110
 
name
111
 
mysqltest
112
 
alter table t1 rename mysqltest.t1;
113
 
ERROR 42S01: Table 'mysqltest.t1' already exists
114
 
select * from t1;
115
 
name
116
 
current
117
 
select * from mysqltest.t1;
118
 
name
119
 
mysqltest
120
 
drop table t1;
121
 
drop database mysqltest;
122
 
create table t1 (n1 int not null, n2 int, n3 int, n4 float,
123
 
unique(n1),
124
 
key (n1, n2, n3, n4),
125
 
key (n2, n3, n4, n1),
126
 
key (n3, n4, n1, n2),
127
 
key (n4, n1, n2, n3) );
128
 
alter table t1;
129
 
show keys from t1;
130
 
Table   Unique  Key_name        Seq_in_index    Column_name
131
 
t1      YES     n1      1       n1
132
 
t1      NO      n1_2    1       n1
133
 
t1      NO      n1_2    2       n2
134
 
t1      NO      n1_2    3       n3
135
 
t1      NO      n1_2    4       n4
136
 
t1      NO      n2      1       n2
137
 
t1      NO      n2      2       n3
138
 
t1      NO      n2      3       n4
139
 
t1      NO      n2      4       n1
140
 
t1      NO      n3      1       n3
141
 
t1      NO      n3      2       n4
142
 
t1      NO      n3      3       n1
143
 
t1      NO      n3      4       n2
144
 
t1      NO      n4      1       n4
145
 
t1      NO      n4      2       n1
146
 
t1      NO      n4      3       n2
147
 
t1      NO      n4      4       n3
148
 
set autocommit=0;
149
 
begin;
150
 
insert into t1 values(10,RAND()*1000,RAND()*1000,RAND());
151
 
insert into t1 values(9,RAND()*1000,RAND()*1000,RAND());
152
 
insert into t1 values(8,RAND()*1000,RAND()*1000,RAND());
153
 
insert into t1 values(7,RAND()*1000,RAND()*1000,RAND());
154
 
insert into t1 values(6,RAND()*1000,RAND()*1000,RAND());
155
 
insert into t1 values(5,RAND()*1000,RAND()*1000,RAND());
156
 
insert into t1 values(4,RAND()*1000,RAND()*1000,RAND());
157
 
insert into t1 values(3,RAND()*1000,RAND()*1000,RAND());
158
 
insert into t1 values(2,RAND()*1000,RAND()*1000,RAND());
159
 
insert into t1 values(1,RAND()*1000,RAND()*1000,RAND());
160
 
commit;
161
 
set autocommit=1;
162
 
alter table t1 enable keys;
163
 
Warnings:
164
 
Note    1031    Table storage engine for 't1' doesn't have this option
165
 
show keys from t1;
166
 
Table   Unique  Key_name        Seq_in_index    Column_name
167
 
t1      YES     n1      1       n1
168
 
t1      NO      n1_2    1       n1
169
 
t1      NO      n1_2    2       n2
170
 
t1      NO      n1_2    3       n3
171
 
t1      NO      n1_2    4       n4
172
 
t1      NO      n2      1       n2
173
 
t1      NO      n2      2       n3
174
 
t1      NO      n2      3       n4
175
 
t1      NO      n2      4       n1
176
 
t1      NO      n3      1       n3
177
 
t1      NO      n3      2       n4
178
 
t1      NO      n3      3       n1
179
 
t1      NO      n3      4       n2
180
 
t1      NO      n4      1       n4
181
 
t1      NO      n4      2       n1
182
 
t1      NO      n4      3       n2
183
 
t1      NO      n4      4       n3
184
 
drop table t1;
185
 
create table t1 (i int not null auto_increment primary key);
186
 
alter table t1 rename t2;
187
 
alter table t2 rename t1, add c char(10) comment "no comment";
188
 
show columns from t1;
189
 
Field   Type    Null    Default Default_is_NULL On_Update
190
 
i       INTEGER NO              NO      
191
 
c       VARCHAR YES             YES     
192
 
drop table t1;
193
 
create table t1 (a int, b int);
194
 
set autocommit=0;
195
 
begin;
196
 
insert into t1 values(1,100), (2,100), (3, 100);
197
 
insert into t1 values(1,99), (2,99), (3, 99);
198
 
insert into t1 values(1,98), (2,98), (3, 98);
199
 
insert into t1 values(1,97), (2,97), (3, 97);
200
 
insert into t1 values(1,96), (2,96), (3, 96);
201
 
insert into t1 values(1,95), (2,95), (3, 95);
202
 
insert into t1 values(1,94), (2,94), (3, 94);
203
 
insert into t1 values(1,93), (2,93), (3, 93);
204
 
insert into t1 values(1,92), (2,92), (3, 92);
205
 
insert into t1 values(1,91), (2,91), (3, 91);
206
 
insert into t1 values(1,90), (2,90), (3, 90);
207
 
insert into t1 values(1,89), (2,89), (3, 89);
208
 
insert into t1 values(1,88), (2,88), (3, 88);
209
 
insert into t1 values(1,87), (2,87), (3, 87);
210
 
insert into t1 values(1,86), (2,86), (3, 86);
211
 
insert into t1 values(1,85), (2,85), (3, 85);
212
 
insert into t1 values(1,84), (2,84), (3, 84);
213
 
insert into t1 values(1,83), (2,83), (3, 83);
214
 
insert into t1 values(1,82), (2,82), (3, 82);
215
 
insert into t1 values(1,81), (2,81), (3, 81);
216
 
insert into t1 values(1,80), (2,80), (3, 80);
217
 
insert into t1 values(1,79), (2,79), (3, 79);
218
 
insert into t1 values(1,78), (2,78), (3, 78);
219
 
insert into t1 values(1,77), (2,77), (3, 77);
220
 
insert into t1 values(1,76), (2,76), (3, 76);
221
 
insert into t1 values(1,75), (2,75), (3, 75);
222
 
insert into t1 values(1,74), (2,74), (3, 74);
223
 
insert into t1 values(1,73), (2,73), (3, 73);
224
 
insert into t1 values(1,72), (2,72), (3, 72);
225
 
insert into t1 values(1,71), (2,71), (3, 71);
226
 
insert into t1 values(1,70), (2,70), (3, 70);
227
 
insert into t1 values(1,69), (2,69), (3, 69);
228
 
insert into t1 values(1,68), (2,68), (3, 68);
229
 
insert into t1 values(1,67), (2,67), (3, 67);
230
 
insert into t1 values(1,66), (2,66), (3, 66);
231
 
insert into t1 values(1,65), (2,65), (3, 65);
232
 
insert into t1 values(1,64), (2,64), (3, 64);
233
 
insert into t1 values(1,63), (2,63), (3, 63);
234
 
insert into t1 values(1,62), (2,62), (3, 62);
235
 
insert into t1 values(1,61), (2,61), (3, 61);
236
 
insert into t1 values(1,60), (2,60), (3, 60);
237
 
insert into t1 values(1,59), (2,59), (3, 59);
238
 
insert into t1 values(1,58), (2,58), (3, 58);
239
 
insert into t1 values(1,57), (2,57), (3, 57);
240
 
insert into t1 values(1,56), (2,56), (3, 56);
241
 
insert into t1 values(1,55), (2,55), (3, 55);
242
 
insert into t1 values(1,54), (2,54), (3, 54);
243
 
insert into t1 values(1,53), (2,53), (3, 53);
244
 
insert into t1 values(1,52), (2,52), (3, 52);
245
 
insert into t1 values(1,51), (2,51), (3, 51);
246
 
insert into t1 values(1,50), (2,50), (3, 50);
247
 
insert into t1 values(1,49), (2,49), (3, 49);
248
 
insert into t1 values(1,48), (2,48), (3, 48);
249
 
insert into t1 values(1,47), (2,47), (3, 47);
250
 
insert into t1 values(1,46), (2,46), (3, 46);
251
 
insert into t1 values(1,45), (2,45), (3, 45);
252
 
insert into t1 values(1,44), (2,44), (3, 44);
253
 
insert into t1 values(1,43), (2,43), (3, 43);
254
 
insert into t1 values(1,42), (2,42), (3, 42);
255
 
insert into t1 values(1,41), (2,41), (3, 41);
256
 
insert into t1 values(1,40), (2,40), (3, 40);
257
 
insert into t1 values(1,39), (2,39), (3, 39);
258
 
insert into t1 values(1,38), (2,38), (3, 38);
259
 
insert into t1 values(1,37), (2,37), (3, 37);
260
 
insert into t1 values(1,36), (2,36), (3, 36);
261
 
insert into t1 values(1,35), (2,35), (3, 35);
262
 
insert into t1 values(1,34), (2,34), (3, 34);
263
 
insert into t1 values(1,33), (2,33), (3, 33);
264
 
insert into t1 values(1,32), (2,32), (3, 32);
265
 
insert into t1 values(1,31), (2,31), (3, 31);
266
 
insert into t1 values(1,30), (2,30), (3, 30);
267
 
insert into t1 values(1,29), (2,29), (3, 29);
268
 
insert into t1 values(1,28), (2,28), (3, 28);
269
 
insert into t1 values(1,27), (2,27), (3, 27);
270
 
insert into t1 values(1,26), (2,26), (3, 26);
271
 
insert into t1 values(1,25), (2,25), (3, 25);
272
 
insert into t1 values(1,24), (2,24), (3, 24);
273
 
insert into t1 values(1,23), (2,23), (3, 23);
274
 
insert into t1 values(1,22), (2,22), (3, 22);
275
 
insert into t1 values(1,21), (2,21), (3, 21);
276
 
insert into t1 values(1,20), (2,20), (3, 20);
277
 
insert into t1 values(1,19), (2,19), (3, 19);
278
 
insert into t1 values(1,18), (2,18), (3, 18);
279
 
insert into t1 values(1,17), (2,17), (3, 17);
280
 
insert into t1 values(1,16), (2,16), (3, 16);
281
 
insert into t1 values(1,15), (2,15), (3, 15);
282
 
insert into t1 values(1,14), (2,14), (3, 14);
283
 
insert into t1 values(1,13), (2,13), (3, 13);
284
 
insert into t1 values(1,12), (2,12), (3, 12);
285
 
insert into t1 values(1,11), (2,11), (3, 11);
286
 
insert into t1 values(1,10), (2,10), (3, 10);
287
 
insert into t1 values(1,9), (2,9), (3, 9);
288
 
insert into t1 values(1,8), (2,8), (3, 8);
289
 
insert into t1 values(1,7), (2,7), (3, 7);
290
 
insert into t1 values(1,6), (2,6), (3, 6);
291
 
insert into t1 values(1,5), (2,5), (3, 5);
292
 
insert into t1 values(1,4), (2,4), (3, 4);
293
 
insert into t1 values(1,3), (2,3), (3, 3);
294
 
insert into t1 values(1,2), (2,2), (3, 2);
295
 
insert into t1 values(1,1), (2,1), (3, 1);
296
 
commit;
297
 
set autocommit=1;
298
 
alter table t1 add unique (a,b), add key (b);
299
 
show keys from t1;
300
 
Table   Unique  Key_name        Seq_in_index    Column_name
301
 
t1      YES     a       1       a
302
 
t1      YES     a       2       b
303
 
t1      NO      b       1       b
304
 
analyze table t1;
305
 
Table   Op      Msg_type        Msg_text
306
 
test.t1 analyze status  OK
307
 
show keys from t1;
308
 
Table   Unique  Key_name        Seq_in_index    Column_name
309
 
t1      YES     a       1       a
310
 
t1      YES     a       2       b
311
 
t1      NO      b       1       b
312
 
drop table t1;
313
 
CREATE TEMPORARY TABLE t1 (
314
 
Host varchar(16) NOT NULL default '',
315
 
User varchar(16) NOT NULL default '',
316
 
PRIMARY KEY  (Host,User),
317
 
KEY  (Host)
318
 
) ENGINE=MyISAM;
319
 
ALTER TABLE t1 DISABLE KEYS;
320
 
INSERT INTO t1 VALUES ('localhost','root'),('localhost','');
321
 
ALTER TABLE t1 ENABLE KEYS;
322
 
CHECK TABLES t1;
323
 
Table   Op      Msg_type        Msg_text
324
 
test.t1 check   status  OK
325
 
ALTER TABLE t1 RENAME t2;
326
 
select * from t2;
327
 
Host    User
328
 
localhost       
329
 
localhost       root
330
 
DROP TABLE t2;
331
 
create table t1 (a int);
332
 
alter table t1 rename to ``;
333
 
ERROR 42000: Incorrect table name ''
334
 
rename table t1 to ``;
335
 
ERROR 42000: Incorrect table name ''
336
 
drop table t1;
337
 
drop table if exists t1;
338
 
Warnings:
339
 
Note    1051    Unknown table 't1'
340
 
create TEMPORARY table t1 ( a varchar(10) not null primary key ) engine=myisam;
341
 
flush tables;
342
 
alter table t1 modify a varchar(10);
343
 
flush tables;
344
 
alter table t1 modify a varchar(10) not null;
345
 
drop table if exists t1;
346
 
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;
347
 
insert into t1 (a,b,c,d,e,f,g,h,i) values(1,1,1,1,1,1,1,1,1);
348
 
show table status like 't1';
349
 
Session Schema  Name    Type    Engine  Version Rows    Avg_row_length  Table_size      Auto_increment
350
 
#       test    t1      TEMPORARY       MyISAM  #       #       #       #       #
351
 
alter table t1 modify a int;
352
 
show table status like 't1';
353
 
Session Schema  Name    Type    Engine  Version Rows    Avg_row_length  Table_size      Auto_increment
354
 
#       test    t1      TEMPORARY       MyISAM  #       #       #       #       #
355
 
drop table t1;
356
 
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;
357
 
insert into t1 (a) values(1);
358
 
show table status like 't1';
359
 
Session Schema  Name    Type    Engine  Version Rows    Avg_row_length  Table_size      Auto_increment
360
 
#       test    t1      TEMPORARY       MyISAM  #       #       #       #       #
361
 
drop table t1;
362
 
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE);
363
 
ALTER TABLE t1 DROP PRIMARY KEY;
364
 
SHOW CREATE TABLE t1;
365
 
Table   Create Table
366
 
t1      CREATE TABLE `t1` (
367
 
  `a` INT NOT NULL,
368
 
  `b` INT DEFAULT NULL,
369
 
  UNIQUE KEY `b` (`b`)
370
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
371
 
ALTER TABLE t1 DROP PRIMARY KEY;
372
 
ERROR 42000: Can't DROP 'PRIMARY'; check that column/key exists
373
 
DROP TABLE t1;
374
 
create table t1 (a int, b int, key(a));
375
 
insert into t1 values (1,1), (2,2);
376
 
alter table t1 drop key no_such_key;
377
 
ERROR 42000: Can't DROP 'no_such_key'; check that column/key exists
378
 
alter table t1 drop key a;
379
 
drop table t1;
380
 
CREATE TEMPORARY TABLE T12207(a int) ENGINE=MYISAM;
381
 
ALTER TABLE T12207 DISCARD TABLESPACE;
382
 
ERROR HY000: Table storage engine for 'T12207' doesn't have this option
383
 
DROP TABLE T12207;
384
 
create table t1 ( a timestamp );
385
 
alter table t1 add unique ( a(1) );
386
 
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
387
 
drop table t1;
388
 
drop table if exists t1;
389
 
create table t1 (a int, key(a));
390
 
show indexes from t1;
391
 
Table   Unique  Key_name        Seq_in_index    Column_name
392
 
t1      NO      a       1       a
393
 
"this used not to disable the index"
394
 
alter table t1 modify a int;
395
 
show indexes from t1;
396
 
Table   Unique  Key_name        Seq_in_index    Column_name
397
 
t1      NO      a       1       a
398
 
alter table t1 enable keys;
399
 
Warnings:
400
 
Note    1031    Table storage engine for 't1' doesn't have this option
401
 
show indexes from t1;
402
 
Table   Unique  Key_name        Seq_in_index    Column_name
403
 
t1      NO      a       1       a
404
 
alter table t1 modify a bigint;
405
 
show indexes from t1;
406
 
Table   Unique  Key_name        Seq_in_index    Column_name
407
 
t1      NO      a       1       a
408
 
alter table t1 enable keys;
409
 
Warnings:
410
 
Note    1031    Table storage engine for 't1' doesn't have this option
411
 
show indexes from t1;
412
 
Table   Unique  Key_name        Seq_in_index    Column_name
413
 
t1      NO      a       1       a
414
 
alter table t1 add b char(10);
415
 
show indexes from t1;
416
 
Table   Unique  Key_name        Seq_in_index    Column_name
417
 
t1      NO      a       1       a
418
 
alter table t1 add c decimal(10,2);
419
 
show indexes from t1;
420
 
Table   Unique  Key_name        Seq_in_index    Column_name
421
 
t1      NO      a       1       a
422
 
"this however did"
423
 
alter table t1;
424
 
show indexes from t1;
425
 
Table   Unique  Key_name        Seq_in_index    Column_name
426
 
t1      NO      a       1       a
427
 
desc t1;
428
 
Field   Type    Null    Default Default_is_NULL On_Update
429
 
a       BIGINT  YES             YES     
430
 
b       VARCHAR YES             YES     
431
 
c       DECIMAL YES             YES     
432
 
alter table t1 add d decimal(15,5);
433
 
"The key should still be disabled"
434
 
show indexes from t1;
435
 
Table   Unique  Key_name        Seq_in_index    Column_name
436
 
t1      NO      a       1       a
437
 
drop table t1;
438
 
"Now will test with one unique index"
439
 
create table t1(a int, b char(10), unique(a));
440
 
show indexes from t1;
441
 
Table   Unique  Key_name        Seq_in_index    Column_name
442
 
t1      YES     a       1       a
443
 
alter table t1;
444
 
show indexes from t1;
445
 
Table   Unique  Key_name        Seq_in_index    Column_name
446
 
t1      YES     a       1       a
447
 
alter table t1 enable keys;
448
 
Warnings:
449
 
Note    1031    Table storage engine for 't1' doesn't have this option
450
 
"If no copy on noop change, this won't touch the data file"
451
 
"Unique index, no change"
452
 
alter table t1 modify a int;
453
 
show indexes from t1;
454
 
Table   Unique  Key_name        Seq_in_index    Column_name
455
 
t1      YES     a       1       a
456
 
"Change the type implying data copy"
457
 
"Unique index, no change"
458
 
alter table t1 modify a bigint;
459
 
show indexes from t1;
460
 
Table   Unique  Key_name        Seq_in_index    Column_name
461
 
t1      YES     a       1       a
462
 
alter table t1 modify a bigint;
463
 
show indexes from t1;
464
 
Table   Unique  Key_name        Seq_in_index    Column_name
465
 
t1      YES     a       1       a
466
 
alter table t1 modify a int;
467
 
show indexes from t1;
468
 
Table   Unique  Key_name        Seq_in_index    Column_name
469
 
t1      YES     a       1       a
470
 
drop table t1;
471
 
"Now will test with one unique and one non-unique index"
472
 
create table t1(a int, b char(10), unique(a), key(b));
473
 
show indexes from t1;
474
 
Table   Unique  Key_name        Seq_in_index    Column_name
475
 
t1      YES     a       1       a
476
 
t1      NO      b       1       b
477
 
alter table t1;
478
 
show indexes from t1;
479
 
Table   Unique  Key_name        Seq_in_index    Column_name
480
 
t1      YES     a       1       a
481
 
t1      NO      b       1       b
482
 
alter table t1 enable keys;
483
 
Warnings:
484
 
Note    1031    Table storage engine for 't1' doesn't have this option
485
 
"If no copy on noop change, this won't touch the data file"
486
 
"The non-unique index will be disabled"
487
 
alter table t1 modify a int;
488
 
show indexes from t1;
489
 
Table   Unique  Key_name        Seq_in_index    Column_name
490
 
t1      YES     a       1       a
491
 
t1      NO      b       1       b
492
 
alter table t1 enable keys;
493
 
Warnings:
494
 
Note    1031    Table storage engine for 't1' doesn't have this option
495
 
show indexes from t1;
496
 
Table   Unique  Key_name        Seq_in_index    Column_name
497
 
t1      YES     a       1       a
498
 
t1      NO      b       1       b
499
 
"Change the type implying data copy"
500
 
"The non-unique index will be disabled"
501
 
alter table t1 modify a bigint;
502
 
show indexes from t1;
503
 
Table   Unique  Key_name        Seq_in_index    Column_name
504
 
t1      YES     a       1       a
505
 
t1      NO      b       1       b
506
 
"Change again the type, but leave the indexes as_is"
507
 
alter table t1 modify a int;
508
 
show indexes from t1;
509
 
Table   Unique  Key_name        Seq_in_index    Column_name
510
 
t1      YES     a       1       a
511
 
t1      NO      b       1       b
512
 
"Try the same. When data is no copied on similar tables, this is noop"
513
 
alter table t1 modify a int;
514
 
show indexes from t1;
515
 
Table   Unique  Key_name        Seq_in_index    Column_name
516
 
t1      YES     a       1       a
517
 
t1      NO      b       1       b
518
 
drop table t1;
519
 
create database mysqltest;
520
 
create table t1 (c1 int);
521
 
alter table t1 rename mysqltest.t1;
522
 
drop table t1;
523
 
ERROR 42S02: Unknown table 't1'
524
 
alter table mysqltest.t1 rename t1;
525
 
drop table t1;
526
 
create table t1 (c1 int);
527
 
use mysqltest;
528
 
drop database mysqltest;
529
 
alter table test.t1 rename t1;
530
 
ERROR 3D000: No schema selected
531
 
alter table test.t1 rename test.t1;
532
 
use test;
533
 
drop table t1;
534
 
CREATE TABLE t1(a INT) ROW_FORMAT=COMPACT;
535
 
CREATE INDEX i1 ON t1(a);
536
 
SHOW CREATE TABLE t1;
537
 
Table   Create Table
538
 
t1      CREATE TABLE `t1` (
539
 
  `a` INT DEFAULT NULL,
540
 
  KEY `i1` (`a`)
541
 
) ENGINE=DEFAULT ROW_FORMAT='COMPACT' COLLATE = utf8_general_ci
542
 
DROP INDEX i1 ON t1;
543
 
SHOW CREATE TABLE t1;
544
 
Table   Create Table
545
 
t1      CREATE TABLE `t1` (
546
 
  `a` INT DEFAULT NULL
547
 
) ENGINE=DEFAULT ROW_FORMAT='COMPACT' COLLATE = utf8_general_ci
548
 
DROP TABLE t1;
549
 
DROP TABLE IF EXISTS bug24219;
550
 
DROP TABLE IF EXISTS bug24219_2;
551
 
CREATE TABLE bug24219 (a INT, INDEX(a));
552
 
SHOW INDEX FROM bug24219;
553
 
Table   Unique  Key_name        Seq_in_index    Column_name
554
 
bug24219        NO      a       1       a
555
 
ALTER TABLE bug24219 RENAME TO bug24219_2, DISABLE KEYS;
556
 
Warnings:
557
 
Note    1031    Table storage engine for 'bug24219' doesn't have this option
558
 
SHOW INDEX FROM bug24219_2;
559
 
Table   Unique  Key_name        Seq_in_index    Column_name
560
 
bug24219_2      NO      a       1       a
561
 
DROP TABLE bug24219_2;
562
 
drop table if exists table_24562;
563
 
create table table_24562(
564
 
section int,
565
 
subsection int,
566
 
title varchar(50));
567
 
insert into table_24562 values
568
 
(1, 0, "Introduction"),
569
 
(1, 1, "Authors"),
570
 
(1, 2, "Acknowledgements"),
571
 
(2, 0, "Basics"),
572
 
(2, 1, "Syntax"),
573
 
(2, 2, "Client"),
574
 
(2, 3, "Server"),
575
 
(3, 0, "Intermediate"),
576
 
(3, 1, "Complex queries"),
577
 
(3, 2, "Stored Procedures"),
578
 
(3, 3, "Stored Functions"),
579
 
(4, 0, "Advanced"),
580
 
(4, 1, "Replication"),
581
 
(4, 2, "Load balancing"),
582
 
(4, 3, "High availability"),
583
 
(5, 0, "Conclusion");
584
 
select * from table_24562;
585
 
section subsection      title
586
 
1       0       Introduction
587
 
1       1       Authors
588
 
1       2       Acknowledgements
589
 
2       0       Basics
590
 
2       1       Syntax
591
 
2       2       Client
592
 
2       3       Server
593
 
3       0       Intermediate
594
 
3       1       Complex queries
595
 
3       2       Stored Procedures
596
 
3       3       Stored Functions
597
 
4       0       Advanced
598
 
4       1       Replication
599
 
4       2       Load balancing
600
 
4       3       High availability
601
 
5       0       Conclusion
602
 
alter table table_24562 add column reviewer varchar(20),
603
 
order by title;
604
 
select * from table_24562;
605
 
section subsection      title   reviewer
606
 
1       2       Acknowledgements        NULL
607
 
4       0       Advanced        NULL
608
 
1       1       Authors NULL
609
 
2       0       Basics  NULL
610
 
2       2       Client  NULL
611
 
3       1       Complex queries NULL
612
 
5       0       Conclusion      NULL
613
 
4       3       High availability       NULL
614
 
3       0       Intermediate    NULL
615
 
1       0       Introduction    NULL
616
 
4       2       Load balancing  NULL
617
 
4       1       Replication     NULL
618
 
2       3       Server  NULL
619
 
3       3       Stored Functions        NULL
620
 
3       2       Stored Procedures       NULL
621
 
2       1       Syntax  NULL
622
 
update table_24562 set reviewer="Me" where section=2;
623
 
update table_24562 set reviewer="You" where section=3;
624
 
alter table table_24562
625
 
order by section ASC, subsection DESC;
626
 
select * from table_24562;
627
 
section subsection      title   reviewer
628
 
1       2       Acknowledgements        NULL
629
 
1       1       Authors NULL
630
 
1       0       Introduction    NULL
631
 
2       3       Server  Me
632
 
2       2       Client  Me
633
 
2       1       Syntax  Me
634
 
2       0       Basics  Me
635
 
3       3       Stored Functions        You
636
 
3       2       Stored Procedures       You
637
 
3       1       Complex queries You
638
 
3       0       Intermediate    You
639
 
4       3       High availability       NULL
640
 
4       2       Load balancing  NULL
641
 
4       1       Replication     NULL
642
 
4       0       Advanced        NULL
643
 
5       0       Conclusion      NULL
644
 
alter table table_24562
645
 
order by table_24562.subsection ASC, table_24562.section DESC;
646
 
select * from table_24562;
647
 
section subsection      title   reviewer
648
 
5       0       Conclusion      NULL
649
 
4       0       Advanced        NULL
650
 
3       0       Intermediate    You
651
 
2       0       Basics  Me
652
 
1       0       Introduction    NULL
653
 
4       1       Replication     NULL
654
 
3       1       Complex queries You
655
 
2       1       Syntax  Me
656
 
1       1       Authors NULL
657
 
4       2       Load balancing  NULL
658
 
3       2       Stored Procedures       You
659
 
2       2       Client  Me
660
 
1       2       Acknowledgements        NULL
661
 
4       3       High availability       NULL
662
 
3       3       Stored Functions        You
663
 
2       3       Server  Me
664
 
alter table table_24562 order by 12;
665
 
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near '12' at line 1
666
 
alter table table_24562 order by (section + 12);
667
 
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near '(section + 12)' at line 1
668
 
alter table table_24562 order by length(title);
669
 
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near '(title)' at line 1
670
 
alter table table_24562 order by no_such_col;
671
 
ERROR 42S22: Unknown column 'no_such_col' in 'order clause'
672
 
drop table table_24562;
673
 
create table t1 (mycol int not null);
674
 
alter table t1 alter column mycol set default 0;
675
 
desc t1;
676
 
Field   Type    Null    Default Default_is_NULL On_Update
677
 
mycol   INTEGER NO      0       NO      
678
 
drop table t1;
679
 
create TEMPORARY table t1(id int primary key auto_increment) engine=MEMORY;
680
 
insert into t1 values (null);
681
 
insert into t1 values (null);
682
 
select * from t1;
683
 
id
684
 
1
685
 
2
686
 
alter table t1 auto_increment = 50;
687
 
alter table t1 engine = myisam;
688
 
insert into t1 values (null);
689
 
select * from t1;
690
 
id
691
 
1
692
 
2
693
 
50
694
 
alter table t1 engine = MEMORY;
695
 
insert into t1 values (null);
696
 
select * from t1;
697
 
id
698
 
1
699
 
2
700
 
50
701
 
51
702
 
drop table t1;
703
 
create table t1 (v varchar(32));
704
 
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
705
 
select * from t1;
706
 
v
707
 
def
708
 
abc
709
 
hij
710
 
3r4f
711
 
alter table t1 change v v2 varchar(32);
712
 
select * from t1;
713
 
v2
714
 
def
715
 
abc
716
 
hij
717
 
3r4f
718
 
alter table t1 change v2 v varchar(64);
719
 
select * from t1;
720
 
v
721
 
def
722
 
abc
723
 
hij
724
 
3r4f
725
 
update t1 set v = 'lmn' where v = 'hij';
726
 
select * from t1;
727
 
v
728
 
def
729
 
abc
730
 
lmn
731
 
3r4f
732
 
alter table t1 add i int auto_increment not null primary key first;
733
 
select * from t1;
734
 
i       v
735
 
1       def
736
 
2       abc
737
 
3       lmn
738
 
4       3r4f
739
 
update t1 set i=5 where i=3;
740
 
select * from t1;
741
 
i       v
742
 
1       def
743
 
2       abc
744
 
4       3r4f
745
 
5       lmn
746
 
alter table t1 change i i bigint;
747
 
select * from t1;
748
 
i       v
749
 
1       def
750
 
2       abc
751
 
4       3r4f
752
 
5       lmn
753
 
alter table t1 add unique key (i, v);
754
 
select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
755
 
i       v
756
 
4       3r4f
757
 
drop table t1;
758
 
create TEMPORARY table t1 (t varchar(255) default null, key t (t(80))) engine=myisam;
759
 
alter table t1 change t t text;
760
 
drop table t1;
761
 
CREATE TABLE t1 (s CHAR(8));
762
 
INSERT INTO t1 VALUES ('test');
763
 
SELECT LENGTH(s) FROM t1;
764
 
LENGTH(s)
765
 
4
766
 
ALTER TABLE t1 MODIFY s CHAR(10);
767
 
SELECT LENGTH(s) FROM t1;
768
 
LENGTH(s)
769
 
4
770
 
DROP TABLE t1;
771
 
CREATE TABLE t1 (s varbinary(8));
772
 
INSERT INTO t1 VALUES ('test');
773
 
SELECT LENGTH(s) FROM t1;
774
 
LENGTH(s)
775
 
4
776
 
SELECT HEX(s) FROM t1;
777
 
HEX(s)
778
 
74657374
779
 
ALTER TABLE t1 MODIFY s varbinary(10);
780
 
SELECT HEX(s) FROM t1;
781
 
HEX(s)
782
 
74657374
783
 
SELECT LENGTH(s) FROM t1;
784
 
LENGTH(s)
785
 
4
786
 
DROP TABLE t1;
787
 
CREATE TABLE t1 (v VARCHAR(3), b INT);
788
 
INSERT INTO t1 VALUES ('abc', 5);
789
 
SELECT * FROM t1;
790
 
v       b
791
 
abc     5
792
 
ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4);
793
 
SELECT * FROM t1;
794
 
v       b
795
 
abc     5
796
 
DROP TABLE t1;
797
 
End of 5.0 tests
798
 
DROP TABLE IF EXISTS `t+1`, `t+2`;
799
 
CREATE TABLE `t+1` (c1 INT);
800
 
ALTER TABLE  `t+1` RENAME `t+2`;
801
 
CREATE TABLE `t+1` (c1 INT);
802
 
ALTER TABLE  `t+1` RENAME `t+2`;
803
 
ERROR 42S01: Table 'test.t+2' already exists
804
 
DROP TABLE   `t+1`, `t+2`;
805
 
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
806
 
ALTER TABLE  `tt+1` RENAME `tt+2`;
807
 
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
808
 
ALTER TABLE  `tt+1` RENAME `tt+2`;
809
 
ERROR 42S01: Table 'test.#tt+2' already exists
810
 
SHOW CREATE TABLE `tt+1`;
811
 
Table   Create Table
812
 
tt+1    CREATE TEMPORARY TABLE `tt+1` (
813
 
  `c1` INT DEFAULT NULL
814
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
815
 
SHOW CREATE TABLE `tt+2`;
816
 
Table   Create Table
817
 
tt+2    CREATE TEMPORARY TABLE `tt+2` (
818
 
  `c1` INT DEFAULT NULL
819
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
820
 
DROP TABLE   `tt+1`, `tt+2`;
821
 
CREATE TEMPORARY TABLE `#sql1` (c1 INT);
822
 
CREATE TEMPORARY TABLE `@0023sql2` (c1 INT);
823
 
SHOW TABLES;
824
 
Tables_in_test
825
 
#sql1
826
 
@0023sql2
827
 
ALTER TABLE `#sql1`      RENAME `@0023sql1`;
828
 
ALTER TABLE `@0023sql2`  RENAME `#sql2`;
829
 
SHOW TABLES;
830
 
Tables_in_test
831
 
#sql2
832
 
@0023sql1
833
 
INSERT INTO `#sql2`      VALUES (1);
834
 
INSERT INTO `@0023sql1`  VALUES (2);
835
 
SHOW CREATE TABLE `#sql2`;
836
 
Table   Create Table
837
 
#sql2   CREATE TEMPORARY TABLE `#sql2` (
838
 
  `c1` INT DEFAULT NULL
839
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
840
 
SHOW CREATE TABLE `@0023sql1`;
841
 
Table   Create Table
842
 
@0023sql1       CREATE TEMPORARY TABLE `@0023sql1` (
843
 
  `c1` INT DEFAULT NULL
844
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
845
 
DROP TABLE `#sql2`, `@0023sql1`;
846
 
DROP TABLE IF EXISTS t1;
847
 
DROP TABLE IF EXISTS t2;
848
 
CREATE TABLE t1 (
849
 
int_field INTEGER NOT NULL,
850
 
char_field CHAR(10),
851
 
INDEX(`int_field`)
852
 
);
853
 
DESCRIBE t1;
854
 
Field   Type    Null    Default Default_is_NULL On_Update
855
 
int_field       INTEGER NO              NO      
856
 
char_field      VARCHAR YES             YES     
857
 
SHOW INDEXES FROM t1;
858
 
Table   Unique  Key_name        Seq_in_index    Column_name
859
 
t1      NO      int_field       1       int_field
860
 
INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet");
861
 
"Non-copy data change - new frm, but old data and index files"
862
 
ALTER TABLE t1 CHANGE int_field unsigned_int_field INTEGER NOT NULL, RENAME t2;
863
 
SELECT * FROM t1 ORDER BY int_field;
864
 
ERROR 42S02: Unknown table 'test.t1'
865
 
SELECT * FROM t2 ORDER BY unsigned_int_field;
866
 
unsigned_int_field      char_field
867
 
1       edno
868
 
1       edno
869
 
2       dve
870
 
3       tri
871
 
5       pet
872
 
DESCRIBE t2;
873
 
Field   Type    Null    Default Default_is_NULL On_Update
874
 
unsigned_int_field      INTEGER NO              NO      
875
 
char_field      VARCHAR YES             YES     
876
 
DESCRIBE t2;
877
 
Field   Type    Null    Default Default_is_NULL On_Update
878
 
unsigned_int_field      INTEGER NO              NO      
879
 
char_field      VARCHAR YES             YES     
880
 
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT NOT NULL;
881
 
DESCRIBE t2;
882
 
Field   Type    Null    Default Default_is_NULL On_Update
883
 
unsigned_int_field      BIGINT  NO              NO      
884
 
char_field      VARCHAR YES             YES     
885
 
DROP TABLE t2;
886
 
CREATE TABLE t1 (f1 INT, f2 INT, f3 INT);
887
 
INSERT INTO t1 VALUES (1, 2, NULL);
888
 
SELECT * FROM t1;
889
 
f1      f2      f3
890
 
1       2       NULL
891
 
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f1;
892
 
SELECT * FROM t1;
893
 
f1      f3      f2
894
 
1       NULL    2
895
 
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2;
896
 
SELECT * FROM t1;
897
 
f1      f2      f3
898
 
1       2       NULL
899
 
DROP TABLE t1;