Commit 6116d017 authored by unknown's avatar unknown

bug#10952

  "alter table from MyISAM to MERGE lost data without errors and warnings"
  Add new handlerton flag which prevent user from altering table storage
  engine to storage engines which would lose data. Both 'blackhole' and 
  'merge' are marked with the new flag.
  Tests included.


mysql-test/r/blackhole.result:
  test for bug#10952
mysql-test/r/merge.result:
  test for bug#10952
mysql-test/t/blackhole.test:
  test for bug#10952
mysql-test/t/merge.test:
  test for bug#10952
sql/ha_blackhole.cc:
  Bug#10952
    shouldn't be able to alter a table into a blackhole
sql/ha_myisammrg.cc:
  Bug#10952
    shouldn't be able to alter a table into a merge
sql/handler.h:
  Bug#10952
    new handlerton flag
sql/sql_table.cc:
  Bug#10952
    If alter is changing engine, check if new engine allows creating table
    via ALTER statement.
parent b5732e7c
......@@ -123,3 +123,11 @@ master-bin.000001 # Query 1 # use `test`; create table t3 like t1
master-bin.000001 # Query 1 # use `test`; insert into t1 select * from t3
master-bin.000001 # Query 1 # use `test`; replace into t1 select * from t3
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=blackhole;
ERROR HY000: Table storage engine for 't1' doesn't have this option
drop table t1;
......@@ -768,3 +768,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;
......@@ -128,3 +128,15 @@ show binlog events;
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=blackhole;
drop table t1;
# End of 5.0 tests
......@@ -379,3 +379,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
......@@ -47,7 +47,7 @@ handlerton blackhole_hton= {
NULL, /* create_cursor_read_view */
NULL, /* set_cursor_read_view */
NULL, /* close_cursor_read_view */
HTON_CAN_RECREATE
HTON_CAN_RECREATE | HTON_ALTER_CANNOT_CREATE
};
/*****************************************************************************
......
......@@ -55,7 +55,7 @@ handlerton myisammrg_hton= {
NULL, /* create_cursor_read_view */
NULL, /* set_cursor_read_view */
NULL, /* close_cursor_read_view */
HTON_CAN_RECREATE
HTON_CAN_RECREATE | HTON_ALTER_CANNOT_CREATE
};
......
......@@ -408,6 +408,7 @@ struct show_table_alias_st {
#define HTON_ALTER_NOT_SUPPORTED (1 << 1) //Engine does not support alter
#define HTON_CAN_RECREATE (1 << 2) //Delete all is used fro truncate
#define HTON_HIDDEN (1 << 3) //Engine does not appear in lists
#define HTON_ALTER_CANNOT_CREATE (1 << 4) //Cannot use alter to create
typedef struct st_thd_trans
{
......
......@@ -3313,7 +3313,9 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
DBUG_PRINT("info", ("old type: %d new type: %d", old_db_type, 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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment