Conceptual
Login

Run ANALYZE After a Bulk Load or the Planner Is Guessing

The planner chooses between a scan and an index from statistics that autovacuum refreshes on a schedule, so right after you import a million rows, restore a dump, or create a table in a migration, those statistics still describe the old, empty table. The result is a plan built for ten rows running against ten million. A single ANALYZE tablename after the load — and in a restored test database before you benchmark anything — removes an entire class of mysterious slowness.

Questions this Concept answers

  • Why is a query often slow immediately after a large import?