Tested two case, which belongs to the legacy of the previous blog:
- InnoDB How to load a data dictionary
- What did flush tables do?
Let's take a look at the InnoDB load data dictionary:
First Use: SELECT * from TT;
1. Create a Handler object
function Call Stack:
Open_binary_frm
Get_new_handler
Innobase_create_handler
Ha_innobase::ha_innobase
Based on the single instance Handlerton + table_share two parameters, the handler object is created, and the assignment table->file. The server layer operates on the InnoDB, which is done through this interface.
2. Open Innobase_share
Innobase_share is the INNODB layer to a table definition, the global shared structure, protected by Innobase_share_mutex.
The Innobase_open_tables hash table holds all the innobase_share.
This completes the initialization of a innobase_share structure.
3. Load the data dictionary:
Initializing the dict_table_t in Innodb_share
Steps:
Mutex_enter (& (Dict_sys->mutex));
dict_sys_t: The whole system data dictionary, the global Dict_sys_t*dict_sys;
Includes:hash_table_t*table_hash;/*!< hash table of the tables, based
Includes: ut_list_base_node_t (dict_table_t) table_lru;/*!< LRU LIST of tables */
Dict_table_get
Dict_table_get_low
Presence: Dict_table_check_if_in_cache_low: Remove from the hash table and update the LRU list.
Not present: dict_load_table
1. Load table Definition
2. Load Columns
3. Load Index
4. Load FOREIGN key
Note: The array dictionary uses two structure storage, one hash is convenient to query, and the other is the LRU linked list, which is used for buffer substitution.
Flush tables;
Reload_acl_and_cache:
1. Empty Query_cache: Use Structure_guard_mutex lock.
2. Close_cached_tables: Off is not used. Use the Lock_open lock for protection.
3. Increment: refresh_version
Free_cache_entry:free off the table in Table_cache
Inter_close_table: Empty Io_cache
CLOSEFRM:
- Close Handler
- Free Innobase_share
- Release Table_share: Removed from Table_def_cache.
Record Binlog:
Flush Talbes Records the binlog of statement.
Note: If flush tables with read lock is used: The global read lock will be used with Meta lock.
Conclusion:
For a table, flush_tables altogether closed table, Table_share, Handler, Innobase_share. Only the dict_table_t data dictionary is retained.
Flush tables does not close in use and when table is used again, it finds that version has changed, closes it, and turns it back on.