HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

When are InnoDB table index statistics updated?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
areinnodbstatisticsupdatedwhenindextable

Problem

In a vanilla build of MySQL 5.5.20, when are InnoDB table index statistics updated? What events trigger such updates? I've seen comments suggesting that the following might trigger it:

  • table is opened for first time



  • query is run against table



  • ANALYZE TABLE



  • size of table changes by some threshold

Solution

You should look for this variable

mysql> show variables like '%metadata%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| innodb_stats_on_metadata | ON    |
+--------------------------+-------+
1 row in set (0.00 sec)

mysql>


According to the MySQL Docs, when innodb_stats_on_metadata is set (by default), InnoDB updates statistics during metadata statements such as SHOW TABLE STATUS or SHOW INDEX, or when accessing the INFORMATION_SCHEMA tables TABLES or STATISTICS. (These updates are similar to what happens for ANALYZE TABLE.) When disabled, InnoDB does not update statistics during these operations. Disabling this variable can improve access speed for schemas that have a large number of tables or indexes. It can also improve the stability of execution plans for queries that involve InnoDB tables.

Once disabled, you would have to run ANALYZE TABLE on the InnoDB tables of your choice. Make sure you have SELECT and INSERT privileges.

Code Snippets

mysql> show variables like '%metadata%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| innodb_stats_on_metadata | ON    |
+--------------------------+-------+
1 row in set (0.00 sec)

mysql>

Context

StackExchange Database Administrators Q#15603, answer score: 5

Revisions (0)

No revisions yet.