diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 95b7b33813152fdcbb02d49c752c3a8703bfa953..086b1209a7ab39158e77a2376daea2fe28481cd0 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -1009,6 +1009,9 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool do_optimize)
   param.out_flag= 0;
   strmov(fixed_name,file->filename);
 
+  // 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 && 
       mi_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK))
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index d9027e3f5b91f2cd1fdf59a4e302d3153ee3a6e4..6d63a0907df64133e65a1bcbcabd4ad25e882325 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -2935,6 +2935,9 @@ bool select_insert::send_data(List<Item> &values)
     }
   }
   
+  // Release latches in case bulk insert takes a long time
+  ha_release_temporary_latches(thd);
+
   error= write_record(thd, table, &info);
   table->auto_increment_field_not_null= FALSE;
   
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 587c0b85ce68324366a15e9f25491860e8d24ad4..437aca866c6f28a880229f4bab4e5c567107fce1 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -10226,6 +10226,9 @@ free_tmp_table(THD *thd, TABLE *entry)
   save_proc_info=thd->proc_info;
   thd_proc_info(thd, "removing tmp table");
 
+  // Release latches since this can take a long time
+  ha_release_temporary_latches(thd);
+
   if (entry->file)
   {
     if (entry->db_stat)
@@ -10274,6 +10277,10 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
     table->file->print_error(error,MYF(0));
     DBUG_RETURN(1);
   }
+
+  // Release latches since this can take a long time
+  ha_release_temporary_latches(thd);
+
   new_table= *table;
   new_table.s= &new_table.share_not_to_be_used;
   new_table.s->db_type= DB_TYPE_MYISAM;