Skip to main content
ANALYZE TABLE creates a manual collection task for collecting CBO statistics. By default, manual collection is a synchronous operation. You can also set it to an asynchronous operation. In asynchronous mode, after you run ANALYZE TABLE, the system immediately returns whether this statement is successful. However, the collection task will be running in the background and you do not have to wait for the result. You can check the status of the task by running SHOW ANALYZE STATUS. Asynchronous collection is suitable for tables with large data volume, whereas synchronous collection is suitable for tables with small data volume. Manual collection tasks are run only once after creation. You do not need to delete manual collection tasks. This statement is supported from v2.4.

Manually collect basic statistics

For more information about basic statistics, see Gather statistics for CBO.

Syntax

Parameter description

  • Collection type
    • FULL: indicates full collection.
    • SAMPLE: indicates sampled collection.
    • If no collection type is specified, full collection is used by default.
  • col_name: columns from which to collect statistics. Separate multiple columns with commas (,). If this parameter is not specified, the entire table is collected.
  • [WITH SYNC | ASYNC MODE]: whether to run the manual collection task in synchronous or asynchronous mode. Synchronous collection is used by default if you do not specify this parameter.
  • PROPERTIES: custom parameters. If PROPERTIES is not specified, the default settings in the fe.conf file are used. The properties that are actually used can be viewed via the Properties column in the output of SHOW ANALYZE STATUS.

Examples

Example 1: Manual full collection
Example 2: Manual sampled collection

Manually collect histograms

For more information about histograms, see Gather statistics for CBO.

Syntax

Parameter description

  • col_name: columns from which to collect statistics. Separate multiple columns with commas (,). If this parameter is not specified, the entire table is collected. This parameter is required for histograms.
  • [WITH SYNC | ASYNC MODE]: whether to run the manual collection task in synchronous or asynchronous mode. Synchronous collection is used by default if you do not specify this parameter.
  • WITH N BUCKETS: N is the number of buckets for histogram collection. If not specified, the default value in fe.conf is used.
  • PROPERTIES: custom parameters. If PROPERTIES is not specified, the default settings in fe.conf are used. The properties that are actually used can be viewed via the Properties column in the output of SHOW ANALYZE STATUS.
The number of rows to collect for a histogram is controlled by multiple parameters. It is the larger value between statistic_sample_collect_rows and table row count * histogram_sample_ratio. The number cannot exceed the value specified by histogram_max_sample_row_count. If the value is exceeded, histogram_max_sample_row_count takes precedence.

Examples

References

SHOW ANALYZE STATUS: view the status of a manual collection task. KILL ANALYZE: cancel a manual collection task that is running. For more information about collecting statistics for CBO, see Gather statistics for CBO.