- MySQL 5.1 Reference Manual :: 12 SQL Statement Syntax :: 12.4 Database Administration Statements :: 12.4.2 Table Maintenance Statements :: 12.4.2.1 ANALYZE TABLE Syntax
-
- MySQL 5.1 Reference Manual
- Preface, Notes, Licenses
- 1 General Information
- 2 Installing and Upgrading MySQL
- 3 Tutorial
- 4 MySQL Programs
- 5 MySQL Server Administration
- 6 Backup and Recovery
- 7 Optimization
- 8 Language Structure
- 9 Internationalization and Localization
- 10 Data Types
- 11 Functions and Operators
- 12 SQL Statement Syntax
- 13 Storage Engines
- 14 High Availability and Scalability
- 15 MySQL Enterprise Monitor
- 16 Replication
- 17 MySQL Cluster NDB 6.X/7.X
- 18 Partitioning
- 19 Stored Programs and Views
- 20 INFORMATION_SCHEMA Tables
- 21 Connectors and APIs
- 22 Extending MySQL
- A MySQL 5.1 Frequently Asked Questions
- B Errors, Error Codes, and Common Problems
- C MySQL Change History
- D Restrictions and Limits
- Index
- Standard Index
- C Function Index
- Command Index
- Function Index
- INFORMATION_SCHEMA Index
- Transaction Isolation Level Index
- JOIN Types Index
- Operator Index
- Option Index
- Privileges Index
- SQL Modes Index
- Status Variable Index
- Statement/Syntax Index
- System Variable Index
ANALYZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE
tbl_name
[,tbl_name
] ...ANALYZE TABLE
analyzes and stores the key distribution for a table. During the analysis, the table is locked with a read lock forMyISAM
. ForInnoDB
the table is locked with a write lock. This statement works withMyISAM
andInnoDB
tables. ForMyISAM
tables, this statement is equivalent to using myisamchk --analyze.For more information on how the analysis works within
InnoDB
, see Section 13.6.14, “Restrictions onInnoDB
Tables”.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.
This statement requires
SELECT
andINSERT
privileges for the table.Beginning with MySQL 5.1.27,
ANALYZE TABLE
is also supported for partitioned tables. Also beginning with MySQL 5.1.27, you can useALTER TABLE ... ANALYZE PARTITION
to analyze one or more partitions; for more information, see Section 12.1.7, “ALTER TABLE
Syntax”, and Section 18.3.3, “Maintenance of Partitions”.ANALYZE TABLE
returns a result set with the following columns.Column Value Table
The table name Op
Always analyze
Msg_type
status
,error
,info
, orwarning
Msg_text
An informational message You can check the stored key distribution with the
SHOW INDEX
statement. See Section 12.4.5.23, “SHOW INDEX
Syntax”.If the table has not changed since the last
ANALYZE TABLE
statement, the table is not analyzed again.By default,
ANALYZE TABLE
statements are written to the binary log so that they will be replicated to replication slaves. Logging can be suppressed with the optionalNO_WRITE_TO_BINLOG
keyword or its aliasLOCAL
.