ANALYZE TABLE
Syntax
ANALYZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE tbl_name [,tbl_name ...] [PERSISTENT FOR ALL|COLUMNS col_name [,col_name ...] INDEXES index_name [,index_name ...]]
Description
ANALYZE TABLE
analyzes and stores the key distribution for a
table (index statistics). During the analysis, the table is locked with a read lock for MyISAM.
For InnoDB the table is locked with a write lock. This statement works with
MyISAM, Aria and InnoDB tables. For MyISAM tables, this statement is equivalent
to using myisamchk --analyze.
For more information on how the analysis works within InnoDB, see InnoDB Restrictions
MariaDB 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.
This statement requires SELECT and INSERT privileges for the table.
By default, ANALYZE TABLE statements are written to the binary log and will be replicated. The NO_WRITE_TO_BINLOG
keyword (LOCAL
is an alias) will ensure the statement is not written to the binary log.
ANALYZE TABLE
is also supported for partitioned tables. You
can use ALTER TABLE ... ANALYZE PARTITION
to analyze one or
more partitions.
MariaDB starting with 10.0.1
MariaDB 10.0.1 extended ANALYZE TABLE to support engine-independent statistics.
The syntax for ANALYZE TABLE has been extended in MariaDB 10.0.1 to allow one to collect statistics only for particular columns or indexes, using PERSISTENT FOR
:
ANALYZE TABLE tbl PERSISTENT FOR COLUMNS (col1,col2,...) INDEXES (idx1,idx2,...); -- empty lists are allowed: ANALYZE TABLE tbl PERSISTENT FOR COLUMNS (col1,col2,...) INDEXES (); ANALYZE TABLE tbl PERSISTENT FOR COLUMNS () INDEXES (idx1,idx2,...); -- the following will only update mysql.table_stat fields: ANALYZE TABLE tbl PERSISTENT FOR COLUMNS () INDEXES (); -- the following is a synonym for old 'analyze table': ANALYZE TABLE tbl PERSISTENT FOR ALL;
Since MariaDB 5.3, the Aria storage engine supports progress reporting for this statement.