MySQL对 DROP TABLE 处理过程(转自老金)

原文http://www.mysqlops.com/2011/02/18/mysql-drop-table-%E5%A4%84%E7%90%86%E8%BF%87%E7%A8%8B.html

 

前几天,在DROP TABLE的时候,所有进程不管是DDL还是DML都被HANG起;直到DROP结束才继续执行;
对这个现象甚其不解;
今天研究了一个 MYSQL 源代码,看其对DROP TABLE 的内部处理过程 ;

当用户发出 DROP TABLE 命令后:

############# MYSQL SERVER 处理删除一个表 ##################    
/* Sql_table.cc  delete (drop) tables. */
bool mysql_rm_table( )

  /*   Execute the drop of a normal or temporary table */
  int mysql_rm_table_part2 ()
 
   /* Remove matching tables from the HANDLER’s hash table.  */
   void mysql_ha_rm_tables () 

    /* Mark all entries with the table as deleted to force an reopen of the table */
    remove_table_from_cache ()
   
   /* remove engine files */  LINE 2024
       int handler::ha_delete_table(const char *name) 
          file->ha_delete_table(path)   line 1991
             int handler::delete_table(const char *name) //删除物理表文件;
                 /* 这里INNODB继承了父类handler ,
                 实际调用的是这个 int ha_innobase::delete_table
                 转到下面:   #### INNODB 处理删除一个表 #### 
                 如果是其他引擎,则直接删除数据文件,往下走*/                
                int mysys::my_delete_with_symlink(const char *name, myf MyFlags)
                  int mysys::my_delete(const char *name, myf MyFlags)     
                 
   /* Delete the table definition file */  LINE 2042 
    int mysys::my_delete()

  /* clear query cache*/ 
      query_cache_invalidate3

    /* writes to BINLOG */
############# INNODB 处理删除一个表 ##################    
/* Drops a table from an InnoDB database.  */
int ha_innobase::delete_table( const char* name) ; // 从INNODB删除表
   int row_drop_table_for_mysql()
     /* 外键关联检查 */
     /* 锁住数据字典(独占锁)*/
        /* Serialize data dictionary operations with dictionary mutex:
        row_mysql_lock_data_dictionary(trx);
            
     /* 更新数字字典(MEMDB,information_schema), line 3178 */
        que_eval_sql(info, “PROCEDURE DROP_TABLE_PROC () IS/n”
        /*这里是通过一个PROCEDURE来处理的*/
          
     /* 更新数字字典(CACHE) */
        void dict_table_remove_from_cache(dict_table_t* table))
          
     /* 删除数据文件
          /* Deletes a single-table tablespace */
          ibool fil_delete_tablespace()
      
            /* Frees a space object from the tablespace memory cache*/
            ibool fil_space_free ()
      
            /* Deletes a file. The file has to be closed before calling this. */
            ibool os_file_delete ()
              unlink((const char*)name);     
        
     /* 释放锁 */
        row_mysql_unlock_data_dictionary(trx);
 
DROP TABLE大概就是这么一个过程 ;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值