diff --git a/mysql-test/suite/versioning/r/vtmd.result b/mysql-test/suite/versioning/r/vtmd.result index ad72da94df3..92c922569fa 100644 --- a/mysql-test/suite/versioning/r/vtmd.result +++ b/mysql-test/suite/versioning/r/vtmd.result @@ -37,7 +37,7 @@ set @start= null; select start from tmp_vtmd for system_time all order by start limit 1 into @start; select @start > 0 and @start < @inf; select -start + 0 = @start as A_start, +start >= @start as A_start, (@start:= end) and end = @inf as B_end, name, substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name @@ -45,12 +45,12 @@ from tmp_vtmd for system_time all; drop table tmp_vtmd; end~~ set versioning_alter_history= keep; -create or replace table t0 (x int) with system versioning; +create table t0 (z int) with system versioning; show tables; Tables_in_test t0 set versioning_alter_history= survive; -create or replace table t0 (x int) with system versioning; +create or replace table t0 (y int) with system versioning; show tables; Tables_in_test t0 @@ -75,14 +75,18 @@ A_start B_end name C_archive_name set versioning_alter_history= keep; drop table t0; set versioning_alter_history= survive; -create or replace table t0 (x int) with system versioning; +create table t0 (x int) with system versioning; ERROR HY000: VTMD error: `test.t0_vtmd` exists and not empty! +drop table t0_vtmd; +create table t0 (y int) with system versioning; +create or replace table t0 (x int) with system versioning; alter table t0 add column (y int); call check_vtmd('t0_vtmd'); @start > 0 and @start < @inf 1 A_start B_end name C_archive_name 1 0 t0 t0_ +1 0 t0 t0_ 1 1 t0 NULL call drop_archives('t0_vtmd'); drop table t0_vtmd; diff --git a/mysql-test/suite/versioning/t/vtmd.test b/mysql-test/suite/versioning/t/vtmd.test index 8ff2f64dc73..5024739fbe5 100644 --- a/mysql-test/suite/versioning/t/vtmd.test +++ b/mysql-test/suite/versioning/t/vtmd.test @@ -46,7 +46,7 @@ begin select start from tmp_vtmd for system_time all order by start limit 1 into @start; select @start > 0 and @start < @inf; select - start + 0 = @start as A_start, + start >= @start as A_start, (@start:= end) and end = @inf as B_end, name, substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name @@ -58,10 +58,10 @@ delimiter ;~~ # create set versioning_alter_history= keep; -create or replace table t0 (x int) with system versioning; +create table t0 (z int) with system versioning; show tables; set versioning_alter_history= survive; -create or replace table t0 (x int) with system versioning; +create or replace table t0 (y int) with system versioning; show tables; show create table t0_vtmd; call check_vtmd('t0_vtmd'); @@ -70,6 +70,10 @@ set versioning_alter_history= keep; drop table t0; set versioning_alter_history= survive; --error ER_VERS_VTMD_ERROR +create table t0 (x int) with system versioning; + +drop table t0_vtmd; +create table t0 (y int) with system versioning; create or replace table t0 (x int) with system versioning; # alter diff --git a/sql/mysqld.h b/sql/mysqld.h index a30612067ba..47776b8288c 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -211,7 +211,7 @@ enum vers_hide_enum enum vers_alter_history_enum { - VERS_ALTER_HISTORY_KEEP, + VERS_ALTER_HISTORY_KEEP= 0, VERS_ALTER_HISTORY_SURVIVE, VERS_ALTER_HISTORY_DROP }; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 1831eecbd26..3866e661f72 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2438,6 +2438,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, else { char *end; + int frm_delete_error= 0; /* It could happen that table's share in the table definition cache is the only thing that keeps the engine plugin loaded @@ -2476,7 +2477,8 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, // Remove extension for delete *(end= path + path_length - reg_ext_length)= '\0'; - if (thd->lex->sql_command == SQLCOM_DROP_TABLE && + if ((thd->lex->sql_command == SQLCOM_DROP_TABLE || + thd->lex->sql_command == SQLCOM_CREATE_TABLE) && thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE && table_type && table_type != view_pseudo_hton) { @@ -2493,29 +2495,33 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, drop_table: error= ha_delete_table(thd, table_type, path, db, table->table_name, !dont_log_query); + if (!error) + { + /* Delete the table definition file */ + strmov(end,reg_ext); + if (table_type && table_type != view_pseudo_hton && + table_type->discover_table) + { + /* + Table type is using discovery and may not need a .frm file. + Delete it silently if it exists + */ + (void) mysql_file_delete(key_file_frm, path, MYF(0)); + } + else if (mysql_file_delete(key_file_frm, path, + MYF(MY_WME))) + { + frm_delete_error= my_errno; + DBUG_ASSERT(frm_delete_error); + } + } } if (!error) { - int frm_delete_error, trigger_drop_error= 0; - /* Delete the table definition file */ - strmov(end,reg_ext); - if (table_type && table_type != view_pseudo_hton && - table_type->discover_table) - { - /* - Table type is using discovery and may not need a .frm file. - Delete it silently if it exists - */ - (void) mysql_file_delete(key_file_frm, path, MYF(0)); - frm_delete_error= 0; - } - else - frm_delete_error= mysql_file_delete(key_file_frm, path, - MYF(MY_WME)); - if (frm_delete_error) - frm_delete_error= my_errno; - else + int trigger_drop_error= 0; + + if (!frm_delete_error) { non_tmp_table_deleted= TRUE; trigger_drop_error= @@ -2534,7 +2540,10 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, if (!error && vtmd.exists) { + enum_sql_command sql_command= thd->lex->sql_command; + thd->lex->sql_command= SQLCOM_DROP_TABLE; error= vtmd.update(thd); + thd->lex->sql_command= sql_command; if (error) mysql_rename_table(table_type, table->db, vtmd.archive_name(), table->db, table->table_name, NO_FK_CHECKS); @@ -5081,6 +5090,9 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table, VTMD_table vtmd(*create_table); if (vtmd.update(thd)) { + thd->variables.vers_alter_history = VERS_ALTER_HISTORY_KEEP; + mysql_rm_table_no_locks(thd, create_table, 0, 0, 0, 0, 1, 1); + thd->variables.vers_alter_history = VERS_ALTER_HISTORY_SURVIVE; result= 1; goto err; } diff --git a/sql/vtmd.cc b/sql/vtmd.cc index 83a6fb512ef..58d9bb311bb 100644 --- a/sql/vtmd.cc +++ b/sql/vtmd.cc @@ -237,10 +237,9 @@ VTMD_table::update(THD *thd, const char* archive_name) { err: vtmd->file->print_error(error, MYF(0)); - goto quit; } - - result= false; + else + result= local_da.is_error(); } quit: @@ -436,6 +435,8 @@ VTMD_rename::try_rename(THD *thd, LString new_db, LString new_alias, const char if (lock_table_names(thd, &vtmd_tl, 0, thd->variables.lock_wait_timeout, 0)) return true; tdc_remove_table(thd, TDC_RT_REMOVE_ALL, about.db, vtmd_name, false); + if (local_da.is_error()) // just safety check + return true; bool rc= mysql_rename_table(hton, about.db, vtmd_name, new_db, vtmd_new_name,