diff options
Diffstat (limited to 'storage/myisam/ha_myisam.cc')
-rw-r--r-- | storage/myisam/ha_myisam.cc | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index f21845bae63..2fe519da794 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1084,6 +1084,7 @@ int ha_myisam::repair(THD *thd, HA_CHECK ¶m, bool do_optimize) char fixed_name[FN_REFLEN]; MYISAM_SHARE* share = file->s; ha_rows rows= file->state->records; + my_bool locking= 0; DBUG_ENTER("ha_myisam::repair"); param.db_name= table->s->db.str; @@ -1098,12 +1099,18 @@ int ha_myisam::repair(THD *thd, HA_CHECK ¶m, bool do_optimize) // Release latches since this can take a long time ha_release_temporary_latches(thd); - // Don't lock tables if we have used LOCK TABLE - if (! thd->locked_tables_mode && - mi_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK)) + /* + Don't lock tables if we have used LOCK TABLE or if we come from + enable_index() + */ + if (!thd->locked_tables_mode && ! (param.testflag & T_NO_LOCKS)) { - mi_check_print_error(¶m,ER(ER_CANT_LOCK),my_errno); - DBUG_RETURN(HA_ADMIN_FAILED); + locking= 1; + if (mi_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK)) + { + mi_check_print_error(¶m,ER(ER_CANT_LOCK),my_errno); + DBUG_RETURN(HA_ADMIN_FAILED); + } } if (!do_optimize || @@ -1226,7 +1233,7 @@ int ha_myisam::repair(THD *thd, HA_CHECK ¶m, bool do_optimize) update_state_info(¶m, file, 0); } thd_proc_info(thd, old_proc_info); - if (! thd->locked_tables_mode) + if (locking) mi_lock_database(file,F_UNLCK); DBUG_RETURN(error ? HA_ADMIN_FAILED : !optimize_done ? HA_ADMIN_ALREADY_DONE : HA_ADMIN_OK); @@ -1458,8 +1465,16 @@ int ha_myisam::enable_indexes(uint mode) param.op_name= "recreating_index"; param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK | T_CREATE_MISSING_KEYS); + /* + Don't lock and unlock table if it's locked. + Normally table should be locked. This test is mostly for safety. + */ + if (likely(file->lock_type != F_UNLCK)) + param.testflag|= T_NO_LOCKS; + if (file->create_unique_index_by_sort) param.testflag|= T_CREATE_UNIQUE_BY_SORT; + param.myf_rw&= ~MY_WAIT_IF_FULL; param.sort_buffer_length= THDVAR(thd, sort_buffer_size); param.stats_method= (enum_handler_stats_method)THDVAR(thd, stats_method); @@ -1539,7 +1554,7 @@ int ha_myisam::indexes_are_disabled(void) void ha_myisam::start_bulk_insert(ha_rows rows, uint flags) { DBUG_ENTER("ha_myisam::start_bulk_insert"); - THD *thd= current_thd; + THD *thd= table->in_use; ulong size= MY_MIN(thd->variables.read_buff_size, (ulong) (table->s->avg_row_length*rows)); DBUG_PRINT("info",("start_bulk_insert: rows %lu size %lu", @@ -1613,7 +1628,7 @@ int ha_myisam::end_bulk_insert() */ if (((err= enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE)) != 0) && - current_thd->killed) + table->in_use->killed) { delete_all_rows(); /* not crashed, despite being killed during repair */ |