SQL reference (MySQL and MariaDB dialects)

ANALYZE, OPTIMIZE, CHECK and REPAIR TABLE

The table maintenance statements answer as a healthy InnoDB table does; they change nothing.

These statements exist so that tools and scripts that run them get the answer they expect (D83). Raft DB keeps no table statistics and has nothing to repair, so they change nothing.

Syntax#

SQL
{ ANALYZE | OPTIMIZE | CHECK | REPAIR } [NO_WRITE_TO_BINLOG | LOCAL] TABLE
    [db_name.]tbl_name [, [db_name.]tbl_name] ... [option] ...

The options after the table names (QUICK, FAST, EXTENDED, USE_FRM, UPDATE HISTOGRAM ... and so on) are read up to the end of the statement and ignored.

Remarks#

  • The answer has the columns Table, Op, Msg_type, Msg_text. For a table that exists it is status / OK. OPTIMIZE first gives the note that the table does not support optimize and is recreated; REPAIR gives the note that the storage engine does not support repair.
  • A table that does not exist gives Error and status / Operation failed.
  • Each statement works on one or more tables of the current or a named database.
  • The output is identical to MySQL and MariaDB (D83: both dialects).
  • ANALYZE, OPTIMIZE, CHECK or REPAIR without the word TABLE is not accepted: ANALYZE and OPTIMIZE are refused with error 1235, CHECK and REPAIR are a syntax error.
  • Privileges are not checked by these statements in this version.

Examples#

Example:

SQL
ANALYZE TABLE t;
ANALYZE TABLE t, u;
ANALYZE LOCAL TABLE t;
OPTIMIZE TABLE t;
CHECK TABLE t QUICK;
REPAIR TABLE t;
CHECK TABLE c1.u, c1.nope;     -- second row: Error, Operation failed

See also#