Today's Question:  What does your personal desk look like?        GIVE A SHOUT

How does MySQL handle DROP TABLE

  Peter        2012-09-24 11:34:05       4,042        1    

A few days ago, when executing DROP TABLE in MySQL, all processes including DDL and DML were hung until DROP TABLE was completed. I am confused about this phenomenon.

I have reviewed the source codes of MySQL to check how MySQL internally handle DROP TABLE.

When user trigger DROP TABLE command:

########################MySQL SERVER drop table########################

/* 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) //Delete data table
                 /* Here INNODB inherits parent class handler ,
                 it actually calls int ha_innobase::delete_table
                 go to next   #### INNODB handle drop table #### 
                 if it's other engine, directly delete data file, continue*/                
                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 handle drop table ##################    
/* Drops a table from an InnoDB database.  */
int ha_innobase::delete_table( const char* name) ; // Drop table with INNODB
   int row_drop_table_for_mysql()
      /* Serialize data dictionary operations with dictionary mutex:
        row_mysql_lock_data_dictionary(trx);
            
       /* Update dictionary table (MEMDB,information_schema), line 3178 */
        que_eval_sql(info, “PROCEDURE DROP_TABLE_PROC () IS\n”
        /*Here using a PROCEDURE*/
          
        /* update dictionary table(CACHE) */
        void dict_table_remove_from_cache(dict_table_t* table))
          
          /* Delete data file
          /* 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);     
        
     /* release the lock */
        row_mysql_unlock_data_dictionary(trx);


Source : http://www.mysqlops.com/2011/02/18/mysql-drop-table-%e5%a4%84%e7%90%86%e8%bf%87%e7%a8%8b.html

MYSQL  DROP TABLE 

Share on Facebook  Share on Twitter  Share on Weibo  Share on Reddit 

  RELATED


  1 COMMENT


Avanir [Reply]@ 2012-11-08 14:23:29
I was drawn by the hoentsy of what you write