The data dictionary in MySQL is one of the important components of the database. INFORMATION_SCHEMA was first introduced in MySQL 5.0 as a standard-compliant way to retrieve metadata from a running MySQL server. Used to store data metadata, statistical information, and access information about the MySQL server (for example, database name or table name, field data type and access permissions, etc.). Prior to 8.0: 1. Metadata comes from files 2. Use the MEMORY table engine 3. The frm file stores table structure information 4. The opt file records some basic information of each library, including the character set of the library, etc. 5. .TRN and .TRG files are used to store trigger information 5.6> SELECT TABLE_SCHEMA ,ENGINE ,COUNT(*) from information_schema.tables where table_schema in ('information_schema' ,'mysql','performance_schema', 'sys') group by TABLE_SCHEMA ,ENGINE; +--------------------+--------------------+----------+ | TABLE_SCHEMA | ENGINE | COUNT(*) | +--------------------+--------------------+----------+ | information_schema | MEMORY | 49 | | information_schema | MyISAM | 10 | | mysql | CSV | 2 | | mysql | InnoDB | 6 | | mysql | MyISAM | 21 | | performance_schema | PERFORMANCE_SCHEMA | 52 | +--------------------+--------------------+----------+ 5.7> SELECT TABLE_SCHEMA ,ENGINE ,COUNT(*) from information_schema.tables where table_schema in ('information_schema' ,'mysql','performance_schema', 'sys') group by TABLE_SCHEMA ,ENGINE; +--------------------+--------------------+----------+ | TABLE_SCHEMA | ENGINE | COUNT(*) | +--------------------+--------------------+----------+ | information_schema | InnoDB | 10 | | information_schema | MEMORY | 51 | | mysql | CSV | 2 | | mysql | InnoDB | 19 | | mysql | MyISAM | 10 | | performance_schema | PERFORMANCE_SCHEMA | 87 | | sys | NULL | 100 | | sys | InnoDB | 1 | +--------------------+--------------------+----------+ After 8.0: 1. Metadata exists in the table 2. All are moved to MySQL database, changed to innodb table engine, and hidden 3. Information_schema can only be viewed through view 4. All NULLs are views 5. Stored in a separate tablespace mysql.ibd 8.0> select TABLE_SCHEMA,ENGINE,count(*) from tables where TABLE_SCHEMA in ('information_schema','mysql','performance_schema','sys') group by TABLE_SCHEMA,ENGINE; +--------------------+--------------------+----------+ | TABLE_SCHEMA | ENGINE | count(*) | +--------------------+--------------------+----------+ | information_schema | NULL | 65 | | mysql | InnoDB | 31 | | mysql | CSV | 2 | | performance_schema | PERFORMANCE_SCHEMA | 102 | | sys | NULL | 100 | | sys | InnoDB | 1 | +--------------------+--------------------+----------+ Despite some improvements in 5.7, INFORMATION_SCHEMA performance continues to be a major pain point for many of our users. The key reason behind the performance issues in the current INFORMATION_SCHEMA implementation is that queries against INFORMATION_SCHEMA tables are implemented in a way that temporary tables are created during query execution. As follows, when we query the table fragments: 5.7> explain select round(DATA_FREE/1024/1024) as DATA_FREE from information_schema.TABLES where DATA_FREE/1024/1024 > 1024 and TABLE_SCHEMA not in ('information_schema', 'mysql', 'performance_schema', 'sys'); +----+-------------+--------+------+---------------+------+---------+------+------+-----------------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------+------+---------------+------+---------+------+------+-----------------------------------------------------+ | 1 | SIMPLE | TABLES | ALL | NULL | NULL | NULL | NULL | NULL | Using where; Open_full_table; Scanned all databases | +----+-------------+--------+------+---------------+------+---------+------+------+-----------------------------------------------------+ Extra information will include Open_full_table; Scanned all databases.
If a MySQL instance has hundreds of databases, each with hundreds of tables, the INFORMATION_SCHEMA query will eventually read each individual frm file from the file system, causing a lot of I/O reads. And it also ends up consuming more CPU to open the table and prepare the associated in-memory data structures. It does try to use the MySQL server-level table cache (the table_definition_cache system variable), but in large instances there is rarely a table cache large enough to hold all the tables. Therefore, memory usage will increase dramatically, and even OOM may occur. Usually we use the following methods to solve this problem: 1. Split the library table to reduce the number of files opened by a single instance 2. Adjust the number of table_definition_cache and table_open_cache 3. Add physical memory After the release of MySQL 8.0, another option was provided. Since the dictionary table uses the InnoDB engine, the dictionary table can use indexes. The following diagram explains the design differences between MySQL 5.7 and 8.0: 8.0> explain select table_name,table_rows,concat(round(DATA_LENGTH/1024/1024, 2), 'MB') as size,concat(round(INDEX_LENGTH/1024/1024, 2), 'MB') as index_size,DATA_FREE/1024/1024 AS data_free_MB from information_schema.TABLES where table_schema not in ('information_schema','performance_schema','test') order by data_free_MB desc limit 10; +----+-------------+-------+------------+--------+--------------------+------------+---------+-------------------------------+------+----------+----------------------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+--------+--------------------+------------+---------+-------------------------------+------+----------+----------------------------------------------+ | 1 | SIMPLE | cat | NULL | index | PRIMARY | name | 194 | NULL | 1 | 100.00 | Using index; Using temporary; Using filesort | | 1 | SIMPLE | sch | NULL | ref | PRIMARY,catalog_id | catalog_id | 8 | mysql.cat.id | 6 | 50.00 | Using where; Using index | | 1 | SIMPLE | tbl | NULL | ref | schema_id | schema_id | 8 | mysql.sch.id | 52 | 100.00 | Using where | | 1 | SIMPLE | ts | NULL | eq_ref | PRIMARY | PRIMARY | 8 | mysql.tbl.tablespace_id | 1 | 100.00 | NULL | | 1 | SIMPLE | stat | NULL | eq_ref | PRIMARY | PRIMARY | 388 | mysql.sch.name,mysql.tbl.name | 1 | 100.00 | NULL | | 1 | SIMPLE | col | NULL | eq_ref | PRIMARY | PRIMARY | 8 | mysql.tbl.collation_id | 1 | 100.00 | Using index | +----+-------------+-------+------------+--------+--------------------+------------+---------+-------------------------------+------+----------+----------------------------------------------+ The above is a detailed explanation of the MySQL 8.0 dictionary table enhancement. For more information about MySQL 8.0 dictionary table enhancement, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to add Vite support to old Vue projects
>>: Nginx configures the same domain name to support both http and https access
a and href attributes HTML uses <a> to repr...
CSS attribute selectors are amazing. They can hel...
Table of contents 1. Maven Dependency 2. Menu rel...
Generate Linux library The Linux version uses cen...
Table of contents From father to son: 1. In the s...
1. CPU utilization sar -p (view all day) sar -u 1...
You can view the container logs through the docke...
This work uses the knowledge of front-end develop...
This article shares the specific code of JavaScri...
Table of contents Preface 1. for loop 2. while lo...
Table of contents Written in front Two-way encryp...
Below are some common parameters of /etc/my.cnf o...
Today, when I was writing a small program, I used...
1. unlink function For hard links, unlink is used...
The first method: docker installation 1. Pull the...