@@ -2438,6 +2438,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
24382438 else
24392439 {
24402440 char *end;
2441+ int frm_delete_error= 0 ;
24412442 /*
24422443 It could happen that table's share in the table definition cache
24432444 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,
24762477 // Remove extension for delete
24772478 *(end= path + path_length - reg_ext_length)= ' \0 ' ;
24782479
2479- if (thd->lex ->sql_command == SQLCOM_DROP_TABLE &&
2480+ if ((thd->lex ->sql_command == SQLCOM_DROP_TABLE ||
2481+ thd->lex ->sql_command == SQLCOM_CREATE_TABLE) &&
24802482 thd->variables .vers_alter_history == VERS_ALTER_HISTORY_SURVIVE &&
24812483 table_type && table_type != view_pseudo_hton)
24822484 {
@@ -2493,29 +2495,33 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
24932495 drop_table:
24942496 error= ha_delete_table (thd, table_type, path, db, table->table_name ,
24952497 !dont_log_query);
2498+ if (!error)
2499+ {
2500+ /* Delete the table definition file */
2501+ strmov (end,reg_ext);
2502+ if (table_type && table_type != view_pseudo_hton &&
2503+ table_type->discover_table )
2504+ {
2505+ /*
2506+ Table type is using discovery and may not need a .frm file.
2507+ Delete it silently if it exists
2508+ */
2509+ (void ) mysql_file_delete (key_file_frm, path, MYF (0 ));
2510+ }
2511+ else if (mysql_file_delete (key_file_frm, path,
2512+ MYF (MY_WME)))
2513+ {
2514+ frm_delete_error= my_errno;
2515+ DBUG_ASSERT (frm_delete_error);
2516+ }
2517+ }
24962518 }
24972519
24982520 if (!error)
24992521 {
2500- int frm_delete_error, trigger_drop_error= 0 ;
2501- /* Delete the table definition file */
2502- strmov (end,reg_ext);
2503- if (table_type && table_type != view_pseudo_hton &&
2504- table_type->discover_table )
2505- {
2506- /*
2507- Table type is using discovery and may not need a .frm file.
2508- Delete it silently if it exists
2509- */
2510- (void ) mysql_file_delete (key_file_frm, path, MYF (0 ));
2511- frm_delete_error= 0 ;
2512- }
2513- else
2514- frm_delete_error= mysql_file_delete (key_file_frm, path,
2515- MYF (MY_WME));
2516- if (frm_delete_error)
2517- frm_delete_error= my_errno;
2518- else
2522+ int trigger_drop_error= 0 ;
2523+
2524+ if (!frm_delete_error)
25192525 {
25202526 non_tmp_table_deleted= TRUE ;
25212527 trigger_drop_error=
@@ -2534,7 +2540,10 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
25342540
25352541 if (!error && vtmd.exists )
25362542 {
2543+ enum_sql_command sql_command= thd->lex ->sql_command ;
2544+ thd->lex ->sql_command = SQLCOM_DROP_TABLE;
25372545 error= vtmd.update (thd);
2546+ thd->lex ->sql_command = sql_command;
25382547 if (error)
25392548 mysql_rename_table (table_type, table->db , vtmd.archive_name (),
25402549 table->db , table->table_name , NO_FK_CHECKS);
@@ -5081,6 +5090,9 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
50815090 VTMD_table vtmd (*create_table);
50825091 if (vtmd.update (thd))
50835092 {
5093+ thd->variables .vers_alter_history = VERS_ALTER_HISTORY_KEEP;
5094+ mysql_rm_table_no_locks (thd, create_table, 0 , 0 , 0 , 0 , 1 , 1 );
5095+ thd->variables .vers_alter_history = VERS_ALTER_HISTORY_SURVIVE;
50845096 result= 1 ;
50855097 goto err;
50865098 }
0 commit comments