Skip to content

Commit

Permalink
add error code and fix some code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
zbdba committed Sep 1, 2020
1 parent c32037c commit 8a3d1f3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
8 changes: 3 additions & 5 deletions mysql-test/main/merge.result
Expand Up @@ -3038,7 +3038,6 @@ c1 c2
411 421
511 521
#
# MDEV-23485 - Change table to merge engine may cause table data lost.
truncate table m1;
ALTER TABLE m1 ENGINE=MRG_MyISAM UNION=(t1,t2)
INSERT_METHOD=LAST;
Expand Down Expand Up @@ -3447,7 +3446,6 @@ c1 c2
411 421
511 521
#
# MDEV-23485 - Change table to merge engine may cause table data lost.
truncate table m1;
ALTER TABLE m1 ENGINE=MRG_MyISAM UNION=(t1,t2)
INSERT_METHOD=LAST;
Expand Down Expand Up @@ -3924,13 +3922,13 @@ DROP TRIGGER trg1;
DROP TABLE t1;
DROP TABLE m1;
#
# MDEV-23485 - Change table to merge engine may cause table data lost.
#
# MDEV-23485 - Change table to merge engine may cause table data lost.
#
CREATE TABLE t1(a INT);
ALTER TABLE t1 engine=MRG_MYISAM;
drop table t1;
CREATE TABLE t1(a INT);
insert into t1() values(1);
ALTER TABLE t1 engine=MRG_MYISAM;
ERROR HY000: Storage engine MyISAM of the table `test`.`t1` doesn't have this option
ERROR HY000: ALTER TABLE TO MERGE ENGINE is not supported for this operation, The original table is not merge engine and have rows may cause table data lost.
drop table t1;
4 changes: 1 addition & 3 deletions mysql-test/main/merge.test
Expand Up @@ -2346,7 +2346,6 @@ INSERT INTO m1 VALUES (511, 521);
SELECT * FROM m1;
#
--echo #
--echo # MDEV-23485 - Change table to merge engine may cause table data lost.
truncate table m1;
ALTER TABLE m1 ENGINE=MRG_MyISAM UNION=(t1,t2)
INSERT_METHOD=LAST;
Expand Down Expand Up @@ -2514,7 +2513,6 @@ INSERT INTO m1 VALUES (511, 521);
SELECT * FROM m1;
#
--echo #
--echo # MDEV-23485 - Change table to merge engine may cause table data lost.
truncate table m1;
ALTER TABLE m1 ENGINE=MRG_MyISAM UNION=(t1,t2)
INSERT_METHOD=LAST;
Expand Down Expand Up @@ -2932,6 +2930,6 @@ ALTER TABLE t1 engine=MRG_MYISAM;
drop table t1;
CREATE TABLE t1(a INT);
insert into t1() values(1);
--error ER_ILLEGAL_HA
--error ER_ALTER_TO_MERGE_ENGINE_NOT_SUPPORTED
ALTER TABLE t1 engine=MRG_MYISAM;
drop table t1;
2 changes: 2 additions & 0 deletions sql/share/errmsg-utf8.txt
Expand Up @@ -7965,3 +7965,5 @@ ER_NOT_ALLOWED_IN_THIS_CONTEXT
eng "'%-.128s' is not allowed in this context"
ER_DATA_WAS_COMMITED_UNDER_ROLLBACK
eng "Engine %s does not support rollback. Changes where committed during rollback call"
ER_ALTER_TO_MERGE_ENGINE_NOT_SUPPORTED
eng "%s is not supported for this operation, The original table is not merge engine and have rows may cause table data lost."
32 changes: 17 additions & 15 deletions sql/sql_table.cc
Expand Up @@ -10130,31 +10130,33 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
DBUG_RETURN(true);
}

/* MDEV-23485: Change table to merge engine may cause table data lost.
* If we want to change a table to merge engine, the original table
* should't be merge engine table and the table have no rows, otherwise
* may cause table data lost. */
/*
MDEV-23485: Change table to merge engine may cause table data lost.
If we want to change a table to merge engine, the original table
should't be merge engine table and the table have no rows, otherwise
may cause table data lost.
*/
if (table->file->ht->db_type != DB_TYPE_MRG_MYISAM &&
create_info->db_type->db_type == DB_TYPE_MRG_MYISAM) {
create_info->db_type->db_type == DB_TYPE_MRG_MYISAM)
{
READ_RECORD info;
bool have_rows= false;
if (init_read_record(&info, thd, table, NULL, NULL, 1, 1, FALSE)) {
if (init_read_record(&info, thd, table, NULL, NULL, 1, 1, FALSE))
{
DBUG_RETURN(true);
}

while (likely(!(error= info.read_record())))
while (!(error= info.read_record()))
{
have_rows= true;
break;
}

if (have_rows) {
DBUG_PRINT("info", ("The original table is not merge table "
"and have rows doesn't support alter"));
my_error(ER_ILLEGAL_HA, MYF(0), hton_name(table->s->db_type())->str,
alter_ctx.db.str, alter_ctx.table_name.str);
my_error(ER_ALTER_TO_MERGE_ENGINE_NOT_SUPPORTED, MYF(0),
"ALTER TABLE TO MERGE ENGINE");
end_read_record(&info);
DBUG_RETURN(true);
}

end_read_record(&info);
}

if (table->s->tmp_table == NO_TMP_TABLE)
Expand Down

0 comments on commit 8a3d1f3

Please sign in to comment.