简体   繁体   中英

How to “clean” mysql information_schema?

I had a database with tens of thousands of tables in it. As a result the mysql information_schema became extremely slow, affecting overall performance by impacting things like open and close time for tables.

Since all of the tables are Myisam and have their corresponding files in the mysql data directory, I simply moved a bunch of table files to a different database.

That works no problem, however, the performance of the information_schema in the original database does not improve much:

mysql> select count(*) from information_schema.TABLES where table_schema='database_1';
+----------+
| count(*) |
+----------+
|    17374 |
+----------+
1 row in set (1 min 28.68 sec)

compared to the new database:

mysql> select count(*) from information_schema.TABLES where table_schema='database_2';
+----------+
| count(*) |
+----------+
|    16127 |
+----------+
1 row in set (2.15 sec)

It seems some "stuff" must have been been left behind in the information_schema.

Does anyone know what is causing this is and if anything can be done about it?

What is causing the performance hit is disk IO.

The information_schema implementation goes looking for every *.FRM file on disk, to find tables.

When the file has been opened recently, the file is actually in memory already, and no real disk io is done, which leads to fast queries.

When the file has not been opened recently, or has been evicted already, the file io results in disk io, which is very slow.

Given the big number of tables, there is not much to do to speed up the information_schema query itself. A much better improvement is to reduce the number of queries that access the information_schema.

If the schema is stable, consider making a copy of the information_schema into a real table, and query the copy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM