Skip to content
Permalink
Browse files
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
  • Loading branch information
montywi committed Mar 29, 2018
1 parent 0631f20 commit 2dbeebd
Show file tree
Hide file tree
Showing 28 changed files with 842 additions and 847 deletions.
@@ -1,22 +1,61 @@
create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
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 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;
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;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`new_name` int(11) DEFAULT NULL,
`c` varchar(80) DEFAULT 'X',
`e` enum('a','b','c') DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 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);
alter online table t1 modify b int default 5;
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;
Table Create Table
t2 CREATE TEMPORARY TABLE `t2` (
`a` int(11) NOT NULL,
`new_name` int(11) DEFAULT NULL,
`c` varchar(80) DEFAULT 'X',
`e` enum('a','b','c') DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='new comment'
drop table t2;
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;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`new_name` int(11) DEFAULT NULL,
`c` varchar(80) DEFAULT NULL,
`e` enum('a','b','c') DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 COMMENT='new comment'
alter online table t1 page_checksum=1;
alter online table t1 page_checksum=0;
ERROR 0A000: LOCK=NONE is not supported for this operation. Try LOCK=SHARED
drop table t1;
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 drop column b, add b int;
@@ -35,11 +74,25 @@ alter online table t1 engine=memory;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
alter online table t1 rename to t2;
ERROR 0A000: LOCK=NONE/SHARED is not supported for this operation. Try LOCK=EXCLUSIVE
alter online table t1 checksum=1;
ERROR 0A000: LOCK=NONE is not supported for this operation. Try LOCK=SHARED
alter online table t1 add constraint check (b > 0);
ERROR 0A000: LOCK=NONE is not supported for this operation. Try LOCK=SHARED
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;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` int(11) DEFAULT NULL,
`c` varchar(80) DEFAULT NULL,
`e` enum('a','b') DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `c` (`c`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 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);
@@ -8,21 +8,23 @@
# 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'));
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 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;

#
@@ -31,14 +33,30 @@ 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);

alter online table t1 modify b int default 5;
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
#
@@ -62,12 +80,17 @@ alter online table t1 add f int;
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'));
@@ -89,7 +89,7 @@ static handler *partition_create_handler(handlerton *hton,
TABLE_SHARE *share,
MEM_ROOT *mem_root);
static uint partition_flags();
static ulonglong alter_table_flags(ulonglong flags);
static alter_table_operations alter_table_flags(alter_table_operations flags);

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

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

/* Should probably look for my own errors first */
if ((error == HA_ERR_NO_PARTITION_FOUND) &&
! (thd->lex->alter_info.flags & Alter_info::ALTER_TRUNCATE_PARTITION))
! (thd->lex->alter_info.flags & ALTER_TRUNCATE_PARTITION))
{
m_part_info->print_no_partition_found(table, errflag);
DBUG_VOID_RETURN;
@@ -9770,9 +9770,10 @@ handler::Table_flags ha_partition::table_flags() const
alter_table_flags must be on handler/table level, not on hton level
due to the ha_partition hton does not know what the underlying hton is.
*/
ulonglong ha_partition::alter_table_flags(ulonglong flags)

alter_table_operations ha_partition::alter_table_flags(alter_table_operations flags)
{
ulonglong flags_to_return;
alter_table_operations flags_to_return;
DBUG_ENTER("ha_partition::alter_table_flags");

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

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

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

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

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

part_inplace_ctx=
@@ -1188,7 +1188,7 @@ class ha_partition :public handler
wrapper function for handlerton alter_table_flags, since
the ha_partition_hton cannot know all its capabilities
*/
virtual ulonglong alter_table_flags(ulonglong flags);
virtual alter_table_operations alter_table_flags(alter_table_operations flags);
/*
unireg.cc will call the following to make sure that the storage engine
can handle the data it is about to send.

0 comments on commit 2dbeebd

Please sign in to comment.