The planner picks the cheapest plan it can find
For every query, PostgreSQL's planner enumerates several execution plans and picks the one with the lowest estimated cost. The estimate is based on statistics: how many rows in each table, how many distinct values per column, value distribution. Stale or missing statistics → wrong estimates → bad plans.
ANALYZE updates statistics
Autovacuum runs ANALYZE periodically. After bulk loads or major data shifts, run ANALYZE manually so the planner doesn't keep using stale numbers. Cheap and fast — rare to over-do it.
Extended statistics for correlated columns
The planner assumes columns are independent unless told otherwise. If city and country are highly correlated (every "Paris" implies "France"), the planner under-estimates. CREATE STATISTICS teaches it the correlation.