Analyze Table

This command collects statistics about the table which can be used by the query optimizer to find a better plan.

ANALYZE TABLE [db_name.]table_name COMPUTE STATISTICS [analyze_option]

Table statistics

ANALYZE TABLE [db_name.]table_name COMPUTE STATISTICS [NOSCAN]

Collect only basic statistics for the table (number of rows, size in bytes).

NOSCAN
collect only statistics that do not require scanning the whole table (i.e. size in bytes).

Column statistics

ANALYZE TABLE [db_name.]table_name COMPUTE STATISTICS FOR COLUMNS col1 [, col2, ...]

Collect column statistics for the specified columns in addition to table statistics.

Tip

Use this command whenever possible because it collects more statistics so the optimizer can find better plans. Make sure to collect statistics for all columns used by the query.

See also: