~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/r/pbxt/alter_table.result

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

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