分析表Analyze Table

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

收集有关查询优化器可以使用的表的统计信息,以查找更好的计划。Collect statistics about the table that can be used by the query optimizer to find a better plan.

表统计信息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 (that is, 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.

提示

请尽可能使用该命令,因为它能收集更多的统计信息,以便优化器可以找到更好的计划。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: