MySQL对 DROP TABLE的处理过程

发布时间:2021-09-18 12:41:15 作者:chen
来源:亿速云 阅读:152

本篇内容介绍了“MySQL对 DROP TABLE的处理过程”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

前几天,在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大概就是这么一个过程 ;

“MySQL对 DROP TABLE的处理过程”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. Mysql 5.7.20中mysql innodb系统表损坏应该如何处理
  2. mysql删除不用表数据

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql

上一篇:Linux系统怎么更新补丁

下一篇:MySQL数据库的性能分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》