Column statistics missing when running ANALYZE TABLE COMPUTE STATISTICS after ANALYZE TABLE COMPUTE STATISTICS FOR ALL COLUMNS

Only run ANALYZE TABLE COMPUTE STATISTICS FOR ALL COLUMNS to ensure column statistics remain available.

Written by Guilherme Leite

Last published at: April 24th, 2025

Problem

The statistics collected by the ANALYZE TABLE <table> COMPUTE STATISTICS FOR ALL COLUMNS command are then not available when you subsequently run ANALYZE TABLE <table> COMPUTE STATISTICS.

 

You may then notice suboptimal query performance because the query optimizer doesn’t have accurate statistics to generate efficient execution plans.

 

Cause

The ANALYZE TABLE <table> COMPUTE STATISTICS command only computes the sizeInBytes and numRows statistics, not the column statistics. 

 

When you run ANALYZE TABLE <table> COMPUTE STATISTICS, it overwrites the column statistics that ANALYZE TABLE <table> COMPUTE STATISTICS FOR ALL COLUMNS previously computed.

 

Additional context

Certain usage patterns such as running ANALYZE TABLE <table> COMPUTE STATISTICS more frequently than ANALYZE TABLE <table> COMPUTE STATISTICS FOR ALL COLUMNS can exacerbate the issue, leading to the column statistics being frequently overwritten and not available for query optimization.

 

Solution

Ensure you only run ANALYZE TABLE <table> COMPUTE STATISTICS FOR ALL COLUMNS to collect statistics for your tables. 

 

This command computes both the sizeInBytes and numRows statistics, as well as the column statistics, so overwrites the previously computed data with new, more inclusive data.