ANALYZE and pg_statistic
Keep planner statistics current with ANALYZE, inspect pg_statistic, and use extended statistics for correlated columns.
Why ANALYZE?
The query planner needs to estimate row counts and selectivities to pick a good plan. Those estimates come from per-column statistics gathered by ANALYZE.
When to Run ANALYZE
Autovacuum runs ANALYZE automatically based on row-change thresholds. After bulk loads or big DELETEs, run it manually so plans don't degrade:
ANALYZE orders;
ANALYZE (VERBOSE) orders;All lessons in this course
- MVCC and Bloat Causes
- VACUUM, autovacuum, vacuum_cost_delay
- ANALYZE and pg_statistic
- Index-Only Scans and Visibility Map