diff --git a/mysql-test/extra/binlog_tests/blackhole.test b/mysql-test/extra/binlog_tests/blackhole.test index 71aec90e9a0..97243015aba 100644 --- a/mysql-test/extra/binlog_tests/blackhole.test +++ b/mysql-test/extra/binlog_tests/blackhole.test @@ -147,3 +147,15 @@ set autocommit=1; --replace_column 2 # 5 # --replace_regex /table_id: [0-9]+/table_id: #/ show binlog events; + +# +# BUG#10952 - alter table ... lost data without errors and warnings +# +drop table if exists t1; +create table t1 (c char(20)) engine=MyISAM; +insert into t1 values ("Monty"),("WAX"),("Walrus"); +--error 1031 +alter table t1 engine=blackhole; +drop table t1; + +# End of 5.0 tests diff --git a/mysql-test/r/binlog_stm_blackhole.result b/mysql-test/r/binlog_stm_blackhole.result index 90eabc6fa66..d31458f7278 100644 --- a/mysql-test/r/binlog_stm_blackhole.result +++ b/mysql-test/r/binlog_stm_blackhole.result @@ -149,3 +149,11 @@ master-bin.000001 # Query 1 # use `test`; create table t1 (a int) engine=blackho master-bin.000001 # Query 1 # use `test`; BEGIN master-bin.000001 # Query 1 # use `test`; insert into t1 values(1) master-bin.000001 # Query 1 # use `test`; COMMIT +drop table if exists t1; +Warnings: +Note 1051 Unknown table 't1' +create table t1 (c char(20)) engine=MyISAM; +insert into t1 values ("Monty"),("WAX"),("Walrus"); +alter table t1 engine=blackhole; +ERROR HY000: Table storage engine for 't1' doesn't have this option +drop table t1; diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index 538f1fa1a20..2f5f382028a 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -771,3 +771,11 @@ Table Op Msg_type Msg_text test.t1 check status OK test.t2 check status OK drop table t1, t2, t3; +drop table if exists t1; +Warnings: +Note 1051 Unknown table 't1' +create table t1 (c char(20)) engine=MyISAM; +insert into t1 values ("Monty"),("WAX"),("Walrus"); +alter table t1 engine=MERGE; +ERROR HY000: Table storage engine for 't1' doesn't have this option +drop table t1; diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index 9fe7bb787cb..9fee4a03b81 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -382,3 +382,15 @@ check table t1, t2; drop table t1, t2, t3; # End of 4.1 tests + +# +# BUG#10952 - alter table ... lost data without errors and warnings +# +drop table if exists t1; +create table t1 (c char(20)) engine=MyISAM; +insert into t1 values ("Monty"),("WAX"),("Walrus"); +--error 1031 +alter table t1 engine=MERGE; +drop table t1; + +# End of 5.0 tests diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index 1cde37644bc..f4a052cea8a 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -74,7 +74,7 @@ handlerton myisammrg_hton= { NULL, /* Alter table flags */ NULL, /* Alter Tablespace */ NULL, /* Fill Files Table */ - HTON_CAN_RECREATE, + HTON_CAN_RECREATE | HTON_ALTER_CANNOT_CREATE, NULL, /* binlog_func */ NULL, /* binlog_log_query */ NULL /* release_temporary_latches */ diff --git a/sql/handler.h b/sql/handler.h index d988e46b236..afee6bb9f8d 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -603,6 +603,7 @@ struct show_table_alias_st { #define HTON_FLUSH_AFTER_RENAME (1 << 4) #define HTON_NOT_USER_SELECTABLE (1 << 5) #define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported +#define HTON_ALTER_CANNOT_CREATE (1 << 7) //Cannot use alter to create typedef struct st_thd_trans { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index f890f504952..62835f38310 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5098,7 +5098,9 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, ha_resolve_storage_engine_name(old_db_type), ha_resolve_storage_engine_name(new_db_type))); if (ha_check_storage_engine_flag(old_db_type, HTON_ALTER_NOT_SUPPORTED) || - ha_check_storage_engine_flag(new_db_type, HTON_ALTER_NOT_SUPPORTED)) + ha_check_storage_engine_flag(new_db_type, HTON_ALTER_NOT_SUPPORTED) || + (old_db_type != new_db_type && + ha_check_storage_engine_flag(new_db_type, HTON_ALTER_CANNOT_CREATE))) { DBUG_PRINT("info", ("doesn't support alter")); my_error(ER_ILLEGAL_HA, MYF(0), table_name); diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc index e9fd1c2319d..098e44f39ee 100644 --- a/storage/blackhole/ha_blackhole.cc +++ b/storage/blackhole/ha_blackhole.cc @@ -67,7 +67,7 @@ handlerton blackhole_hton= { NULL, /* Alter table flags */ NULL, /* Alter Tablespace */ NULL, /* Fill FILES table */ - HTON_CAN_RECREATE, + HTON_CAN_RECREATE | HTON_ALTER_CANNOT_CREATE, NULL, /* binlog_func */ NULL, /* binlog_log_query */ NULL /* release_temporary_latches */