ANALYZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE
ANALYZE TABLEanalyzes and stores the key distribution for a table. During the analysis, the table is locked with a read lock for
InnoDBthe table is locked with a write lock. This statement works with
MyISAMtables, this statement is equivalent to using myisamchk --analyze.
For more information on how the analysis works within
InnoDB, see Section 13.6.14, “Restrictions on
MySQL Enterprise. For expert advice on optimizing tables, subscribe to the MySQL Enterprise Monitor. For more information, see http://www.mysql.com/products/enterprise/advisors.html.
MySQL uses the stored key distribution to decide the order in which tables should be joined when you perform a join on something other than a constant. In addition, key distributions can be used when deciding which indexes to use for a specific table within a query.
Beginning with MySQL 5.1.27,
ANALYZE TABLEis also supported for partitioned tables. Also beginning with MySQL 5.1.27, you can use
ALTER TABLE ... ANALYZE PARTITIONto analyze one or more partitions; for more information, see Section 12.1.7, “
ALTER TABLESyntax”, and Section 18.3.3, “Maintenance of Partitions”.
ANALYZE TABLEreturns a result set with the following columns.
The table name
An informational message
If the table has not changed since the last
ANALYZE TABLEstatement, the table is not analyzed again.
ANALYZE TABLEstatements are written to the binary log so that they will be replicated to replication slaves. Logging can be suppressed with the optional
NO_WRITE_TO_BINLOGkeyword or its alias