ANALYZE
On this page
Collects statistics for a table.
ANALYZE TABLE table_name [columns [column_name_list | all] [enable | disable]]
The ANALYZE
command manually gathers statistics for a table.
The ANALYZE
command may:
-
Collect column statistics:
-
Row count,
-
Column cardinality (number of unique values in a column),
-
Null count (number of null values in a column).
-
-
Update and create histograms.
The type of statistics collected and histograms built by the ANALYZE
command depends on autostats settings and the ANALYZE
command itself.
In addition to the ANALYZE
command, SingleStore provides automatic statistics collection, which is referred to as autostats.
Warning
ANALYZE
may invalidate plans and cause them to be re-optimized and recompiled the next time the plan is run.ANALYZE
triggers plan invalidation and re-optimization when statistics change and a new plan is estimated to be faster, as described in Plan Invalidation.
Column Statistics Collection
The table below shows when column statistics are collected by the ANALYZE TABLE
command.
Table Settings |
Column statistics collected by |
---|---|
|
No |
|
Yes |
|
Yes |
-
If incremental autostats is enabled for a table (
AUTOSTATS_
):CARDINALITY_ MODE = INCREMENTAL -
ANALYZE
will not gather colum statistics and will return quickly. -
The autostats system updates the table statistics when the table is modified through a DML statement (e.
g. INSERT
,UPDATE
,DELETE
,LOAD DATA
, andTRUNCATE
).The statistics do not need to be re-gathered when ANALYZE
is run.
-
-
Incremental autostats (
AUTOSTATS_
) is not supported for rowstore tables.CARDINALITY_ MODE = INCREMENTAL -
Collecting statistics with
ANALYZE
can be expensive for large tables when incremental autostats is not enabled.You can choose when to run ANALYZE
to best manage the performance impact. -
The
ANALZYE
command overwrites any previous statistics collected on the table. -
Collecting column statistics is strongly recommended for optimal query performance.
-
The autostats settings for a table can be found by querying the OPTIMZER_
STATISTICS information schema view.
Histogram Collection
The ANALYZE
command recollects data for histograms for columns that already have histograms built for them, and creates histograms for columns specified with ENABLE
in the ANALYZE
statement.ANALYZE
regardless of the setting of AUTOSTATS_
SingleStore recommends collecting histograms for columns that are commonly filtered on.
Syntax
The ANALYZE
command has the following forms:
ANALYZE TABLE table_name;ANALYZE TABLE table_name COLUMNS column_name [, ...] ENABLE;ANALYZE TABLE table_name COLUMNS ALL ENABLE;ANALYZE TABLE table_name COLUMNS column_name [, ...] DISABLE;ANALYZE TABLE table_name COLUMNS ALL DISABLE;ANALYZE TABLE table_name DROP;
All forms of ANALYZE
are subject to the following restrictions:
-
ANALYZE
can be run on a master or child aggregator node. -
ANALYZE
requiresSELECT
andALTER
orINSERT
permissions on the target table. -
table_
must be the name of a table in the chosen database.name -
column_
must refer to a column in the tablename table_
.name
ANALYZE TABLE table_ name
Collect column statistics on all columns in table_
if incremental autostats is not enabled.AUTOSTATS_
is set to INCREMENTAL
.
Collects histograms over all columns that have histograms enabled.
Invalidate all plans on this table which were compiled with statistics that are significantly different from the newly observed statistics.
ANALYZE TABLE table_ name COLUMNS column_ name [, . . . ] ENABLE
Enables histogram collection for the listed columns then collects statistics and invalidates plans as described in ANALYZE TABLE table_
.
Histograms will be collected for columns listed in this command and any columns on which histograms were previously enabled.
ANALYZE TABLE table_ name COLUMNS ALL ENABLE
Enables histogram collection for all columns then collects statistics and invalidates plans as described in ANALYZE TABLE table_
.
If the table contains columns which do not support histograms, a warning will be raised for each such column.
Because this command creates a histogram on every column of the table and collects histogram information for each new histogram, please note the following:
-
On very wide tables, this can be expensive to collect, increasing the execution time of the
ANALYZE
command. -
The histograms are stored in memory.
Make sure to plan for the extra memory enabling those histograms will consume. -
Histograms are not always useful to have.
Query the MV_ PROSPECTIVE_ HISTOGRAMS information schema view to check if a column has been identified from your workload, where having a histogram on that column would be beneficial to your queries. -
In some cases sampling stats are better than histograms, see Histograms vs.
Sampling for more information.
Instead of enabling histograms on all columns, SingleStore recommends using the default behavior by setting: default_
.
When default_
is set to CREATE
, if a column is identified at least twice in the MV_
information schema view as potentially benefiting from having a histogram, a histogram for that column will be automatically created and updated at that time.ANALYZE
, and as part of the periodic autostats process.
ANALYZE TABLE table_ name COLUMNS column_ name [, . . . ] DISABLE
Delete histograms on specified columns if present and disable histograms on those columns.
Does not collect any statistics.
ANALYZE TABLE table_ name COLUMNS ALL DISABLE
Delete histograms on all columns of the table if present and disable histograms on all columns.
Does not collect any statistics.
ANALYZE TABLE table_ name DROP
Deletes all stored statistics for a table and disables histograms on any columns for which they have been enabled.
Last modified: July 10, 2025