Skip to main content

ANALYZE

The ANALYZE statement collects statistics about the contents of tables and indexes. The query optimizer uses these statistics to choose better query plans, particularly when deciding which index to use and how to order joins.

Syntax

Description

The ANALYZE statement gathers statistics about the distribution of values in indexes and stores the results in the sqlite_stat1 table (and optionally sqlite_stat4). The query optimizer reads these statistics to make better decisions about:
  • Which index to use for a query
  • The order in which to process tables in a join
  • Whether to use an index or a full table scan

Forms

Examples

Analyze All Tables

Analyze a Specific Table

Viewing Statistics

The statistics are stored in the sqlite_stat1 table:
The stat column contains space-separated integers. The first integer is the total number of rows in the table. Subsequent integers estimate the average number of rows that share the same value for the leftmost N columns of the index.

See Also