panagin1 Absent Member.
Absent Member.
756 views

MySQL - Slow query on information_schema.tables

Recently, I've found slow queries at mysql DB (built in ArcSight ESM):

# Time: 151002 16:39:50

# User@Host: arcsight[arcsight] @ localhost [127.0.0.1]

# Query_time: 62.566705 Lock_time: 0.000034 Rows_sent: 1  Rows_examined: 4106

SET timestamp=1443793190;

SELECT sum(data_length), sum(index_length) FROM information_schema.tables WHERE engine = 'InnoDB';

# Time: 151002 16:41:33

# User@Host: arcsight[arcsight] @ localhost [127.0.0.1]

# Query_time: 72.936992 Lock_time: 0.000032 Rows_sent: 1  Rows_examined: 4106

SET timestamp=1443793293;

SELECT sum(data_length), sum(index_length) FROM information_schema.tables WHERE engine = 'InnoDB';

Google helped with answer:

MySQL by default looks to refresh Innodb statistics each time table is queried from information schema.

... and solution:

set innodb_stats_on_metadata=0.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.

To apply this parameter dynamically (works until restart):

mysql> set global innodb_stats_on_metadata=0;

permanently - add "innodb_stats_on_metadata=0" to /opt/arcsight/logger/data/mysql/my.cnf

Special thanks to @Ray Doty for his tweak "slow_query_log_file = /opt/arcsight/logger/data/mysql/mysql_server-slow.log" from message

https://protect724.hp.com/message/64954#64954

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.