Many of us find INFORMATION_SCHEMA painfully slow to work it when it comes to retrieving table meta data. Many people resort to using file system tools instead to
find for example how much space innodb tables are using and things like it. Besides being just slow accessing information_schema can often impact server performance
dramatically. The cause of majority of this slowness is not opening and closing tables, which can be solved with decent table cache size, and which is very fast for
Innodb but by the fact MySQL by default looks to refresh Innodb statistics each time table is queried from information schema.
The solution is simple, just set innodb_stats_on_metadata=0 which will prevent statistic update when you query information_schema. Most likely
you do not want it anyway. This will not make Innodb to operate without statistics at all as Innodb will still compute statistics for the table first time it opens it.
Here are some numbers from my test box:
mysql> select count(*),sum(data_length) from information_schema.tables; +----------+------------------+ | count(*) | sum(data_length) | +----------+------------------+ | 130 | 2856365892 | +----------+------------------+ 1 row in set (1.08 sec) mysql> set global innodb_stats_on_metadata=0; Query OK, 0 rows affected (0.00 sec) mysql> select count(*),sum(data_length) from information_schema.tables; +----------+------------------+ | count(*) | sum(data_length) | +----------+------------------+ | 130 | 2856365892 | +----------+------------------+ 1 row in set (0.00 sec)
As you can see performance gains are huge.
Note enabling this option will not make information_schema to be stale when it comes to important stuff – data_length for example will be correctly returned by information schema as it changes.
PlanetMySQL Voting: Vote UP / Vote DOWN