summaryrefslogtreecommitdiff
path: root/mysql-test/main/alter_table_online.test
blob: 6ef9661c43b1129605b9fe23e29aa22244f50ac6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#
# Test of ALTER ONLINE TABLE syntax
#

--source include/have_innodb.inc
--source include/have_partition.inc
#
# Test of things that can be done online
#

create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b')) engine=myisam;
insert into t1 (a) values (1),(2),(3);

alter online table t1 modify b int default 5, alter c set default 'X';
alter online table t1 change b new_name int;
alter online table t1 modify e enum('a','b','c');
alter online table t1 comment "new comment";
alter table t1 add constraint q check (a > 0);
alter online table t1 drop constraint q;

# No OPs

alter online table t1 algorithm=INPLACE, lock=NONE;
alter online table t1;
alter table t1 algorithm=INPLACE;
alter table t1 lock=NONE;
show create table t1;
drop table t1;

#
# everything with temporary tables is "online", i.e. without locks
#
create temporary table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
insert into t1 (a) values (1),(2),(3);

alter online table t1 modify b int default 5, alter c set default 'X';
alter online table t1 change b new_name int;
alter online table t1 modify e enum('a','b','c');
alter online table t1 comment "new comment";
alter online table t1 rename to t2;
show create table t2;
drop table t2;

#
# Test also with Aria
#

create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b')) engine=aria;
insert into t1 (a) values (1),(2),(3);
alter online table t1 modify b int default 5;
alter online table t1 change b new_name int;
alter online table t1 modify e enum('a','b','c');
alter online table t1 comment "new comment";
show create table t1;
alter online table t1 page_checksum=1;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 page_checksum=0;
drop table t1;

#
# Test of things that is not possible to do online
#

create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
insert into t1 (a) values (1),(2),(3);

--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 drop column b, add b int;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 modify b bigint;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 modify e enum('c','a','b');
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 modify c varchar(50);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 modify c varchar(100);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 add f int;
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
alter online table t1 engine=memory;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 rename to t2;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 checksum=1;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 add constraint check (b > 0);

alter table t1 engine=innodb;
alter table t1 add index (b);
alter online table t1 add index c (c);
alter online table t1 drop index b;
alter online table t1 comment "new comment";
show create table t1;
drop table t1;

create temporary table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
insert into t1 (a) values (1),(2),(3);

#
# everything with temporary tables is "online", i.e. without locks
#
alter online table t1 drop column b, add b int;
alter online table t1 modify b bigint;
alter online table t1 modify e enum('c','a','b');
alter online table t1 modify c varchar(50);
alter online table t1 modify c varchar(100);
alter online table t1 add f int;
alter online table t1 engine=memory;

alter table t1 engine=innodb;
alter table t1 add index (b);
alter online table t1 add index c (c);
alter online table t1 drop index b;
drop table t1;

#
# Test merge tables
#
create table t1 (a int not null primary key, b int, c varchar(80));
create table t2 (a int not null primary key, b int, c varchar(80));
create table t3 (a int not null primary key, b int, c varchar(80)) engine=merge UNION=(t1);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t3 union=(t1,t2);
drop table t1,t2,t3;

#
# MDEV-9868 Altering a partitioned table comment does a full copy
#
create table t1 (i int) partition by hash(i) partitions 2;
alter online table t1 comment 'test';
drop table t1;

#
# MDEV-9168 altering a column comment does a full copy
#
create table t1 (a int);
alter online table t1 modify a int comment 'test';
drop table t1;

create table t1 (a int) engine=innodb;
alter online table t1 modify a int comment 'test';
drop table t1;

create table t1 (a int) partition by hash(a) partitions 2;
alter online table t1 modify a int comment 'test';
drop table t1;

--echo #
--echo # MDEV-8948 ALTER ... INPLACE does work for BINARY, BLOB
--echo #
#
# ALTER to the same [VAR]BINARY type
#
CREATE TABLE t1 (a BINARY(10));
ALTER TABLE t1 MODIFY a BINARY(10), ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a VARBINARY(10));
ALTER TABLE t1 MODIFY a VARBINARY(10), ALGORITHM=INPLACE;
DROP TABLE t1;

#
# ALTER to the same BLOB variant
#
CREATE TABLE t1 (a TINYBLOB);
ALTER TABLE t1 MODIFY a TINYBLOB, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a MEDIUMBLOB);
ALTER TABLE t1 MODIFY a MEDIUMBLOB, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a BLOB);
ALTER TABLE t1 MODIFY a BLOB, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a LONGBLOB);
ALTER TABLE t1 MODIFY a LONGBLOB, ALGORITHM=INPLACE;
DROP TABLE t1;

#
# ALTER to the same [VAR]CHAR type
#
CREATE TABLE t1 (a CHAR(10));
ALTER TABLE t1 MODIFY a CHAR(10), ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a VARCHAR(10));
ALTER TABLE t1 MODIFY a VARCHAR(10), ALGORITHM=INPLACE;
DROP TABLE t1;


#
# ALTER to the same TEXT variant
#
CREATE TABLE t1 (a TINYTEXT);
ALTER TABLE t1 MODIFY a TINYTEXT, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a MEDIUMTEXT);
ALTER TABLE t1 MODIFY a MEDIUMTEXT, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a TEXT);
ALTER TABLE t1 MODIFY a TEXT, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a LONGTEXT);
ALTER TABLE t1 MODIFY a LONGTEXT, ALGORITHM=INPLACE;
DROP TABLE t1;

#
# ALTER from a non-binary to a binary collation
#
CREATE TABLE t1 (a CHAR(10));
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a CHAR(10) COLLATE latin1_bin, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a VARCHAR(10));
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a VARCHAR(10) COLLATE latin1_bin, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a TINYTEXT);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a TINYTEXT COLLATE latin1_bin, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a MEDIUMTEXT);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a MEDIUMTEXT COLLATE latin1_bin, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a TEXT);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a TEXT COLLATE latin1_bin, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a LONGTEXT);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a LONGTEXT COLLATE latin1_bin, ALGORITHM=INPLACE;
DROP TABLE t1;

#
# ALTER from a binary to a non-binary collation
#
CREATE TABLE t1 (a CHAR(10) COLLATE latin1_bin);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a CHAR(10) COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a VARCHAR(10) COLLATE latin1_bin);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a VARCHAR(10) COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a TINYTEXT COLLATE latin1_bin);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a TINYTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a MEDIUMTEXT COLLATE latin1_bin);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a MEDIUMTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a TEXT COLLATE latin1_bin);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a TEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a LONGTEXT COLLATE latin1_bin);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a LONGTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

#
# ALTER from a non-binary collation to another non-binary collation
#
CREATE TABLE t1 (a CHAR(10) COLLATE latin1_general_ci);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a CHAR(10) COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a VARCHAR(10) COLLATE latin1_general_ci);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a VARCHAR(10) COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a TINYTEXT COLLATE latin1_general_ci);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a TINYTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a MEDIUMTEXT COLLATE latin1_general_ci);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a MEDIUMTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a TEXT COLLATE latin1_general_ci);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a TEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

CREATE TABLE t1 (a LONGTEXT COLLATE latin1_general_ci);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 MODIFY a LONGTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
DROP TABLE t1;

# End of 10.0 tests

#
# MDEV-11335 Changing delay_key_write option for MyISAM table should not copy rows
#
select @@global.delay_key_write;
create table t1 (a int, b int, key(b));
flush tables;
flush status;
show status like 'Feature_delay_key_write';
insert t1 values (1,2),(2,3),(3,4);
show status like 'Feature_delay_key_write';
alter online table t1 delay_key_write=1;
show status like 'Feature_delay_key_write';
flush tables;
insert t1 values (1,2),(2,3),(3,4);
show status like 'Feature_delay_key_write';
alter online table t1 delay_key_write=0;
show status like 'Feature_delay_key_write';
flush tables;
insert t1 values (1,2),(2,3),(3,4);
show status like 'Feature_delay_key_write';
drop table t1;

# End of 10.1 tests