Skip to content

Commit 2dbeebd

Browse files
committed
Changed static const in Alter_info and Alter_online_info to defines
Main reason was to make it easier to print the above structures in a debugger. Additional benefits is that I was able to use same defines for both structures, which simplifes some code. Most of the code is just removing Alter_info:: and Alter_inplace_info:: from alter table flags. Following renames was done: HA_ALTER_FLAGS -> alter_table_operations CHANGE_CREATE_OPTION -> ALTER_CHANGE_CREATE_OPTION Alter_info::ADD_INDEX -> ALTER_ADD_INDEX DROP_INDEX -> ALTER_DROP_INDEX ADD_UNIQUE_INDEX -> ALTER_ADD_UNIQUE_INDEX DROP_UNIQUE_INDEx -> ALTER_DROP_UNIQUE_INDEX ADD_PK_INDEX -> ALTER_ADD_PK_INDEX DROP_PK_INDEX -> ALTER_DROP_PK_INDEX Alter_info:ALTER_ADD_COLUMN -> ALTER_PARSE_ADD_COLUMN Alter_info:ALTER_DROP_COLUMN -> ALTER_PARSE_DROP_COLUMN Alter_inplace_info::ADD_INDEX -> ALTER_ADD_NON_UNIQUE_NON_PRIM_INDEX Alter_inplace_info::DROP_INDEX -> ALTER_DROP_NON_UNIQUE_NON_PRIM_INDEX Other things: - Added typedef alter_table_operatons for alter table flags - DROP CHECK CONSTRAINT can now be done online - Added checks for Aria tables in alter_table_online.test - alter_table_flags now takes an ulonglong as argument. - Don't support online operations if checksum option is used. - sql_lex.cc doesn't add ALTER_ADD_INDEX if index is not created
1 parent 0631f20 commit 2dbeebd

28 files changed

+842
-847
lines changed

mysql-test/r/alter_table_online.result

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,61 @@
1-
create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
1+
create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b')) engine=myisam;
22
insert into t1 (a) values (1),(2),(3);
3-
alter online table t1 modify b int default 5;
3+
alter online table t1 modify b int default 5, alter c set default 'X';
44
alter online table t1 change b new_name int;
55
alter online table t1 modify e enum('a','b','c');
66
alter online table t1 comment "new comment";
7+
alter table t1 add constraint q check (a > 0);
8+
alter online table t1 drop constraint q;
79
alter online table t1 algorithm=INPLACE, lock=NONE;
810
alter online table t1;
911
alter table t1 algorithm=INPLACE;
1012
alter table t1 lock=NONE;
13+
show create table t1;
14+
Table Create Table
15+
t1 CREATE TABLE `t1` (
16+
`a` int(11) NOT NULL,
17+
`new_name` int(11) DEFAULT NULL,
18+
`c` varchar(80) DEFAULT 'X',
19+
`e` enum('a','b','c') DEFAULT NULL,
20+
PRIMARY KEY (`a`)
21+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='new comment'
1122
drop table t1;
1223
create temporary table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
1324
insert into t1 (a) values (1),(2),(3);
14-
alter online table t1 modify b int default 5;
25+
alter online table t1 modify b int default 5, alter c set default 'X';
1526
alter online table t1 change b new_name int;
1627
alter online table t1 modify e enum('a','b','c');
1728
alter online table t1 comment "new comment";
1829
alter online table t1 rename to t2;
30+
show create table t2;
31+
Table Create Table
32+
t2 CREATE TEMPORARY TABLE `t2` (
33+
`a` int(11) NOT NULL,
34+
`new_name` int(11) DEFAULT NULL,
35+
`c` varchar(80) DEFAULT 'X',
36+
`e` enum('a','b','c') DEFAULT NULL,
37+
PRIMARY KEY (`a`)
38+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='new comment'
1939
drop table t2;
40+
create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b')) engine=aria;
41+
insert into t1 (a) values (1),(2),(3);
42+
alter online table t1 modify b int default 5;
43+
alter online table t1 change b new_name int;
44+
alter online table t1 modify e enum('a','b','c');
45+
alter online table t1 comment "new comment";
46+
show create table t1;
47+
Table Create Table
48+
t1 CREATE TABLE `t1` (
49+
`a` int(11) NOT NULL,
50+
`new_name` int(11) DEFAULT NULL,
51+
`c` varchar(80) DEFAULT NULL,
52+
`e` enum('a','b','c') DEFAULT NULL,
53+
PRIMARY KEY (`a`)
54+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 COMMENT='new comment'
55+
alter online table t1 page_checksum=1;
56+
alter online table t1 page_checksum=0;
57+
ERROR 0A000: LOCK=NONE is not supported for this operation. Try LOCK=SHARED
58+
drop table t1;
2059
create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
2160
insert into t1 (a) values (1),(2),(3);
2261
alter online table t1 drop column b, add b int;
@@ -35,11 +74,25 @@ alter online table t1 engine=memory;
3574
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
3675
alter online table t1 rename to t2;
3776
ERROR 0A000: LOCK=NONE/SHARED is not supported for this operation. Try LOCK=EXCLUSIVE
77+
alter online table t1 checksum=1;
78+
ERROR 0A000: LOCK=NONE is not supported for this operation. Try LOCK=SHARED
79+
alter online table t1 add constraint check (b > 0);
80+
ERROR 0A000: LOCK=NONE is not supported for this operation. Try LOCK=SHARED
3881
alter table t1 engine=innodb;
3982
alter table t1 add index (b);
4083
alter online table t1 add index c (c);
4184
alter online table t1 drop index b;
4285
alter online table t1 comment "new comment";
86+
show create table t1;
87+
Table Create Table
88+
t1 CREATE TABLE `t1` (
89+
`a` int(11) NOT NULL,
90+
`b` int(11) DEFAULT NULL,
91+
`c` varchar(80) DEFAULT NULL,
92+
`e` enum('a','b') DEFAULT NULL,
93+
PRIMARY KEY (`a`),
94+
KEY `c` (`c`)
95+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='new comment'
4396
drop table t1;
4497
create temporary table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
4598
insert into t1 (a) values (1),(2),(3);

mysql-test/t/alter_table_online.test

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
88
# Test of things that can be done online
99
#
1010

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

14-
alter online table t1 modify b int default 5;
14+
alter online table t1 modify b int default 5, alter c set default 'X';
1515
alter online table t1 change b new_name int;
1616
alter online table t1 modify e enum('a','b','c');
1717
alter online table t1 comment "new comment";
18+
alter table t1 add constraint q check (a > 0);
19+
alter online table t1 drop constraint q;
1820

1921
# No OPs
2022

2123
alter online table t1 algorithm=INPLACE, lock=NONE;
2224
alter online table t1;
2325
alter table t1 algorithm=INPLACE;
2426
alter table t1 lock=NONE;
25-
27+
show create table t1;
2628
drop table t1;
2729

2830
#
@@ -31,14 +33,30 @@ drop table t1;
3133
create temporary table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
3234
insert into t1 (a) values (1),(2),(3);
3335

34-
alter online table t1 modify b int default 5;
36+
alter online table t1 modify b int default 5, alter c set default 'X';
3537
alter online table t1 change b new_name int;
3638
alter online table t1 modify e enum('a','b','c');
3739
alter online table t1 comment "new comment";
3840
alter online table t1 rename to t2;
39-
41+
show create table t2;
4042
drop table t2;
4143

44+
#
45+
# Test also with Aria
46+
#
47+
48+
create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b')) engine=aria;
49+
insert into t1 (a) values (1),(2),(3);
50+
alter online table t1 modify b int default 5;
51+
alter online table t1 change b new_name int;
52+
alter online table t1 modify e enum('a','b','c');
53+
alter online table t1 comment "new comment";
54+
show create table t1;
55+
alter online table t1 page_checksum=1;
56+
--error ER_ALTER_OPERATION_NOT_SUPPORTED
57+
alter online table t1 page_checksum=0;
58+
drop table t1;
59+
4260
#
4361
# Test of things that is not possible to do online
4462
#
@@ -62,12 +80,17 @@ alter online table t1 add f int;
6280
alter online table t1 engine=memory;
6381
--error ER_ALTER_OPERATION_NOT_SUPPORTED
6482
alter online table t1 rename to t2;
83+
--error ER_ALTER_OPERATION_NOT_SUPPORTED
84+
alter online table t1 checksum=1;
85+
--error ER_ALTER_OPERATION_NOT_SUPPORTED
86+
alter online table t1 add constraint check (b > 0);
6587

6688
alter table t1 engine=innodb;
6789
alter table t1 add index (b);
6890
alter online table t1 add index c (c);
6991
alter online table t1 drop index b;
7092
alter online table t1 comment "new comment";
93+
show create table t1;
7194
drop table t1;
7295

7396
create temporary table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));

sql/ha_partition.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static handler *partition_create_handler(handlerton *hton,
8989
TABLE_SHARE *share,
9090
MEM_ROOT *mem_root);
9191
static uint partition_flags();
92-
static ulonglong alter_table_flags(ulonglong flags);
92+
static alter_table_operations alter_table_flags(alter_table_operations flags);
9393

9494
/*
9595
If frm_error() is called then we will use this to to find out what file
@@ -214,7 +214,7 @@ static uint partition_flags()
214214
return HA_CAN_PARTITION;
215215
}
216216

217-
static ulonglong alter_table_flags(ulonglong /* flags */)
217+
static alter_table_operations alter_table_flags(alter_table_operations flags __attribute__((unused)))
218218
{
219219
return (HA_PARTITION_FUNCTION_SUPPORTED |
220220
HA_FAST_CHANGE_PARTITION);
@@ -1380,7 +1380,7 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
13801380
when ALTER TABLE <CMD> PARTITION ...
13811381
it should only do named partitions, otherwise all partitions
13821382
*/
1383-
if (!(thd->lex->alter_info.flags & Alter_info::ALTER_ADMIN_PARTITION) ||
1383+
if (!(thd->lex->alter_info.flags & ALTER_ADMIN_PARTITION) ||
13841384
part_elem->part_state == PART_ADMIN)
13851385
{
13861386
if (m_is_sub_partitioned)
@@ -9655,7 +9655,7 @@ void ha_partition::print_error(int error, myf errflag)
96559655

96569656
/* Should probably look for my own errors first */
96579657
if ((error == HA_ERR_NO_PARTITION_FOUND) &&
9658-
! (thd->lex->alter_info.flags & Alter_info::ALTER_TRUNCATE_PARTITION))
9658+
! (thd->lex->alter_info.flags & ALTER_TRUNCATE_PARTITION))
96599659
{
96609660
m_part_info->print_no_partition_found(table, errflag);
96619661
DBUG_VOID_RETURN;
@@ -9770,9 +9770,10 @@ handler::Table_flags ha_partition::table_flags() const
97709770
alter_table_flags must be on handler/table level, not on hton level
97719771
due to the ha_partition hton does not know what the underlying hton is.
97729772
*/
9773-
ulonglong ha_partition::alter_table_flags(ulonglong flags)
9773+
9774+
alter_table_operations ha_partition::alter_table_flags(alter_table_operations flags)
97749775
{
9775-
ulonglong flags_to_return;
9776+
alter_table_operations flags_to_return;
97769777
DBUG_ENTER("ha_partition::alter_table_flags");
97779778

97789779
flags_to_return= ht->alter_table_flags(flags);
@@ -9870,7 +9871,7 @@ ha_partition::check_if_supported_inplace_alter(TABLE *altered_table,
98709871
Any other change would set partition_changed in
98719872
prep_alter_part_table() in mysql_alter_table().
98729873
*/
9873-
if (ha_alter_info->alter_info->flags == Alter_info::ALTER_PARTITION)
9874+
if (ha_alter_info->alter_info->flags == ALTER_PARTITION)
98749875
DBUG_RETURN(HA_ALTER_INPLACE_NO_LOCK);
98759876

98769877
part_inplace_ctx=
@@ -9887,7 +9888,7 @@ ha_partition::check_if_supported_inplace_alter(TABLE *altered_table,
98879888
for (index= 0; index <= m_tot_parts; index++)
98889889
part_inplace_ctx->handler_ctx_array[index]= NULL;
98899890

9890-
ha_alter_info->handler_flags |= Alter_inplace_info::ALTER_PARTITIONED;
9891+
ha_alter_info->handler_flags |= ALTER_PARTITIONED;
98919892
for (index= 0; index < m_tot_parts; index++)
98929893
{
98939894
enum_alter_inplace_result p_result=
@@ -9937,7 +9938,7 @@ bool ha_partition::prepare_inplace_alter_table(TABLE *altered_table,
99379938
Changing to similar partitioning, only update metadata.
99389939
Non allowed changes would be catched in prep_alter_part_table().
99399940
*/
9940-
if (ha_alter_info->alter_info->flags == Alter_info::ALTER_PARTITION)
9941+
if (ha_alter_info->alter_info->flags == ALTER_PARTITION)
99419942
DBUG_RETURN(false);
99429943

99439944
part_inplace_ctx=
@@ -9970,7 +9971,7 @@ bool ha_partition::inplace_alter_table(TABLE *altered_table,
99709971
Changing to similar partitioning, only update metadata.
99719972
Non allowed changes would be catched in prep_alter_part_table().
99729973
*/
9973-
if (ha_alter_info->alter_info->flags == Alter_info::ALTER_PARTITION)
9974+
if (ha_alter_info->alter_info->flags == ALTER_PARTITION)
99749975
DBUG_RETURN(false);
99759976

99769977
part_inplace_ctx=
@@ -10010,7 +10011,7 @@ bool ha_partition::commit_inplace_alter_table(TABLE *altered_table,
1001010011
Changing to similar partitioning, only update metadata.
1001110012
Non allowed changes would be catched in prep_alter_part_table().
1001210013
*/
10013-
if (ha_alter_info->alter_info->flags == Alter_info::ALTER_PARTITION)
10014+
if (ha_alter_info->alter_info->flags == ALTER_PARTITION)
1001410015
DBUG_RETURN(false);
1001510016

1001610017
part_inplace_ctx=

sql/ha_partition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ class ha_partition :public handler
11881188
wrapper function for handlerton alter_table_flags, since
11891189
the ha_partition_hton cannot know all its capabilities
11901190
*/
1191-
virtual ulonglong alter_table_flags(ulonglong flags);
1191+
virtual alter_table_operations alter_table_flags(alter_table_operations flags);
11921192
/*
11931193
unireg.cc will call the following to make sure that the storage engine
11941194
can handle the data it is about to send.

0 commit comments

Comments
 (0)