summaryrefslogtreecommitdiff
path: root/mysql-test/t/alter_table_online.test
blob: d9c2a2c4d4f31bfe01bbc004f29f3cf8b24e0350 (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
#
# 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'));
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";

# No OPs

alter online table t1 algorithm=INPLACE, lock=NONE;
alter online table t1;
alter table t1 algorithm=INPLACE;
alter table t1 lock=NONE;

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 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;

drop table t2;

#
# 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;

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";
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;