diff --git a/mysql-test/r/alter_table_online.result b/mysql-test/r/alter_table_online.result index 83e8219154178f2bd85c0761fbb2ac9756ab93c5..1e7bc5e83cd993946f97eeed343c43e2fc559970 100644 --- a/mysql-test/r/alter_table_online.result +++ b/mysql-test/r/alter_table_online.result @@ -11,61 +11,59 @@ 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; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 change b new_name int; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 modify e enum('a','b','c'); -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 comment "new comment"; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 rename to t2; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. 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; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 modify b bigint; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 modify e enum('c','a','b'); -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 modify c varchar(50); -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 modify c varchar(100); -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 add f int; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 engine=memory; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter table t1 engine=innodb; alter table t1 add index (b); alter online table t1 add index c (c); -ERROR HY000: Can't execute the given 'ALTER' command as online alter online table t1 drop index b; -ERROR HY000: Can't execute the given 'ALTER' command as online 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 drop column b, add b int; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 modify b bigint; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 modify e enum('c','a','b'); -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 modify c varchar(50); -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 modify c varchar(100); -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 add f int; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 engine=memory; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter table t1 engine=innodb; alter table t1 add index (b); alter online table t1 add index c (c); -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. alter online table t1 drop index b; -ERROR HY000: Can't execute the given 'ALTER' command as online +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. drop table t1; 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)); diff --git a/mysql-test/t/alter_table_online.test b/mysql-test/t/alter_table_online.test index 19096efe0faa2aa9b4090c3a0d243739c44613f9..a9ce77d14455ec3eadae6784b0f16744e0eb8ae4 100644 --- a/mysql-test/t/alter_table_online.test +++ b/mysql-test/t/alter_table_online.test @@ -1,5 +1,5 @@ # -# Test of alter online table +# Test of ALTER ONLINE TABLE syntax # --source include/have_innodb.inc @@ -29,15 +29,15 @@ 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); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 modify b int default 5; ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 change b new_name int; ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 modify e enum('a','b','c'); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 comment "new comment"; ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 rename to t2; drop table t1; @@ -49,52 +49,50 @@ 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); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 drop column b, add b int; ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 modify b bigint; ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 modify e enum('c','a','b'); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 modify c varchar(50); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 modify c varchar(100); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 add f int; ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 engine=memory; alter table t1 engine=innodb; alter table t1 add index (b); ---error ER_CANT_DO_ONLINE alter online table t1 add index c (c); ---error ER_CANT_DO_ONLINE alter online table t1 drop index b; 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); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 drop column b, add b int; ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 modify b bigint; ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 modify e enum('c','a','b'); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 modify c varchar(50); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 modify c varchar(100); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 add f int; ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 engine=memory; alter table t1 engine=innodb; alter table t1 add index (b); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 add index c (c); ---error ER_CANT_DO_ONLINE +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table t1 drop index b; drop table t1; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 92c78335238724379f6e6e8052a5cf73b81a50cd..77ef72126a1f217f7e69fd888b18f9319fe8ac6e 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -2363,7 +2363,7 @@ struct LEX: public Query_tables_list enum enum_yes_no_unknown tx_chain, tx_release; bool safe_to_cache_query; - bool subqueries, ignore, online; + bool subqueries, ignore; st_parsing_options parsing_options; Alter_info alter_info; /* diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index ea2c51d0bba39f90067f56f33af298063afd5f45..5022972018f9ce9b8887ace474c9c2cfba1af8a0 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -6878,41 +6878,40 @@ string_list: */ alter: - ALTER alter_options TABLE_SYM table_ident + ALTER + { + Lex->name.str= 0; + Lex->name.length= 0; + Lex->sql_command= SQLCOM_ALTER_TABLE; + Lex->duplicates= DUP_ERROR; + Lex->col_list.empty(); + Lex->select_lex.init_order(); + bzero(&Lex->create_info, sizeof(Lex->create_info)); + Lex->create_info.db_type= 0; + Lex->create_info.default_table_charset= NULL; + Lex->create_info.row_type= ROW_TYPE_NOT_USED; + Lex->alter_info.reset(); + Lex->no_write_to_binlog= 0; + Lex->create_info.storage_media= HA_SM_DEFAULT; + DBUG_ASSERT(!Lex->m_sql_cmd); + } + alter_options TABLE_SYM table_ident { - THD *thd= YYTHD; - LEX *lex= thd->lex; - lex->name.str= 0; - lex->name.length= 0; - lex->sql_command= SQLCOM_ALTER_TABLE; - lex->duplicates= DUP_ERROR; - if (!lex->select_lex.add_table_to_list(thd, $4, NULL, + if (!Lex->select_lex.add_table_to_list(YYTHD, $5, NULL, TL_OPTION_UPDATING, TL_READ_NO_INSERT, MDL_SHARED_UPGRADABLE)) MYSQL_YYABORT; - lex->col_list.empty(); - lex->select_lex.init_order(); - lex->select_lex.db= (lex->select_lex.table_list.first)->db; - bzero((char*) &lex->create_info,sizeof(lex->create_info)); - lex->create_info.db_type= 0; - lex->create_info.default_table_charset= NULL; - lex->create_info.row_type= ROW_TYPE_NOT_USED; - lex->alter_info.reset(); - lex->no_write_to_binlog= 0; - lex->create_info.storage_media= HA_SM_DEFAULT; - lex->create_last_non_select_table= lex->last_table(); - DBUG_ASSERT(!lex->m_sql_cmd); + Lex->select_lex.db= (Lex->select_lex.table_list.first)->db; + Lex->create_last_non_select_table= Lex->last_table(); } alter_commands { - THD *thd= YYTHD; - LEX *lex= thd->lex; - if (!lex->m_sql_cmd) + if (!Lex->m_sql_cmd) { /* Create a generic ALTER TABLE statment. */ - lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_alter_table(); - if (lex->m_sql_cmd == NULL) + Lex->m_sql_cmd= new (YYTHD->mem_root) Sql_cmd_alter_table(); + if (Lex->m_sql_cmd == NULL) MYSQL_YYABORT; } } @@ -7586,7 +7585,7 @@ opt_ignore: ; alter_options: - { Lex->ignore= Lex->online= 0;} alter_options_part2 + { Lex->ignore= 0;} alter_options_part2 ; alter_options_part2: @@ -7601,7 +7600,11 @@ alter_option_list: alter_option: IGNORE_SYM { Lex->ignore= 1;} - | ONLINE_SYM { Lex->online= 1;} + | ONLINE_SYM + { + Lex->alter_info.requested_algorithm= + Alter_info::ALTER_TABLE_ALGORITHM_INPLACE; + } opt_restrict: diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 2ac8df005d9d072e0b7afb2b25ac5026f1ec2c44..a0158c9615c2911508586ab38332c01e8470366c 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -1616,14 +1616,15 @@ void ha_myisammrg::append_create_info(String *packet) } -bool ha_myisammrg::check_if_incompatible_data(HA_CREATE_INFO *info, - uint table_changes) +enum_alter_inplace_result +ha_myisammrg::check_if_supported_inplace_alter(TABLE *altered_table, + Alter_inplace_info *ha_alter_info) { /* - For myisammrg, we should always re-generate the mapping file as this - is trivial to do + We always support inplace ALTER in the new API, because old + HA_NO_COPY_ON_ALTER table_flags() hack prevents non-inplace ALTER anyway. */ - return COMPATIBLE_DATA_NO; + return HA_ALTER_INPLACE_EXCLUSIVE_LOCK; } diff --git a/storage/myisammrg/ha_myisammrg.h b/storage/myisammrg/ha_myisammrg.h index 8007e7d04e897ee8e02ad53de9fdb7cbfdc914a7..68c2023c2a5e38526681fca5767f502f5016fab6 100644 --- a/storage/myisammrg/ha_myisammrg.h +++ b/storage/myisammrg/ha_myisammrg.h @@ -145,7 +145,8 @@ public: void append_create_info(String *packet); MYRG_INFO *myrg_info() { return file; } TABLE *table_ptr() { return table; } - bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes); + enum_alter_inplace_result check_if_supported_inplace_alter(TABLE *, + Alter_inplace_info *); int check(THD* thd, HA_CHECK_OPT* check_opt); ha_rows records(); virtual uint count_query_cache_dependant_tables(uint8 *tables_type);