Analyze indexes to optimize queries


ANALYZE [database-name .] [table-name]


The ANALYZE command gathers statistics about indexes and stores them in a special tables in the database where the query optimizer can use them to help make better index choices. If no arguments are given, all indexes in all attached databases are analyzed. If a database name is given as the argument, all indexes in that database are analyzed. If the argument is a table name, then only indexes associated with that table are analyzed.

The database-name can be the name of any attached database. You don't have to supply the database name of non-attached database; if you do, use main.

The initial implementation stores all statistics in a single table named sqlite_stat1. Future enhancements may create additional tables with the same name pattern except with the 1 changed to a different digit. The sqlite_stat1 table can't be erased by the DROP command, but all its content can be deleted with the DELETE statement, which has the same effect.