This section describes how to configure persistent and
non-persistent optimizer statistics for InnoDB
tables.
Persistent optimizer statistics are persisted across server restarts, allowing for greater plan stability and more consistent query performance. Persistent optimizer statistics also provide control and flexibility with these additional benefits:
You can use the
innodb_stats_auto_recalcconfiguration option to control whether statistics are updated automatically after substantial changes to a table.You can use the
STATS_PERSISTENT,STATS_AUTO_RECALC, andSTATS_SAMPLE_PAGESclauses withCREATE TABLEandALTER TABLEstatements to configure optimizer statistics for individual tables.You can query optimizer statistics data in the
mysql.innodb_table_statsandmysql.innodb_index_statstables.You can view the
last_updatecolumn of themysql.innodb_table_statsandmysql.innodb_index_statstables to see when statistics were last updated.You can manually modify the
mysql.innodb_table_statsandmysql.innodb_index_statstables to force a specific query optimization plan or to test alternative plans without modifying the database.
The persistent optimizer statistics feature is enabled by default
(innodb_stats_persistent=ON).
Non-persistent optimizer statistics are cleared on each server restart and after some other operations, and recomputed on the next table access. As a result, different estimates could be produced when recomputing statistics, leading to different choices in execution plans and variations in query performance.
This section also provides information about estimating
ANALYZE TABLE complexity, which may
be useful when attempting to achieve a balance between accurate
statistics and ANALYZE TABLE
execution time.