InnoDB persistent stats got a friendly UI
By Calvin Sun on Apr 11, 2012
Note: this article was originally published on http://blogs.innodb.com on April 11, 2012 by Vasil Dimov.
After introducing InnoDB persistent statistics in MySQL 5.6, in this April Labs release we have dressed it up in a nice UI and refactored the internals a bit to make the code more elegant and straight-forward.
The persistent stats are now controlled globally and can also be overridden at table level, should any table require a different behavior.
The server global flag –innodb-stats-persistent (boolean) now controls whether all InnoDB tables use persistent statistics or not. Keep in mind that if a table is using persistent stats then its statistics will not be updated automatically and you are responsible for running ANALYZE TABLE periodically, whenever you think the table contents has changed too much. Thus the default for –innodb-stats-persistent is currently set to OFF.
The persistent stats ON/OFF setting can be overridden at a table level with a table option like this:
CREATE TABLE t (a INT) ENGINE=INNODB PERSISTENT_STATS=0|1|default;
ALTER TABLE t PERSISTENT_STATS=0|1|default;
where ’0′ means no persistent stats for this table (regardless of the setting of the global –innodb-stats-persistent), ’1′ means to always use persistent stats for this table and ‘default’ means to use the server global setting, whatever it is.
Another goodie is that now you do not need to restart the server if you have manually updated the stats values in mysql.innodb_table_stats and/or mysql.innodb_index_stats and want your changes to take effect. Just do
FLUSH TABLE t;
to force InnoDB to reread what’s in mysql.innodb_table_stats and mysql.innodb_index_stats.
What to expect next? Maybe a fully controlled automatic persistent stats update so you do not have to worry about having to run ANALYZE TABLE periodically but still your query plans are stable? Wouldn’t that be nice?