~/talk

pg_stats: How Postgres Internal Stats Work

Talkat POSETTE: An Event for Postgres 2026 · 2026-06-16..06-18· [databases]
github:richyen
slides:none on file

Shows exactly what pg_stats and pg_statistic contain and how ANALYZE builds them, with concrete numbers: a 1,000,000‑row customers table yields ~17,000 rows (≈17%) for CA and ~4,000 for WY; planner cost math picks a sequential scan at cost ~19,000 versus an index plan at ~32,000. Covers histograms (default 100 buckets, raising to 1,000 gives day‑level precision) and uses pg_stats view plus CREATE STATISTICS (dependencies/ndistinct) to fix correlated columns and tighten estimates.

AI-written summary · about

  1. 0:00Music & introduction
  2. 0:30Why Postgres ignores your index
  3. 2:00How the query planner thinks
  4. 4:34Exploring pg_statistic and pg_stats
  5. 6:10Understanding null fractions and cardinality
  6. 8:15Most common values
  7. 9:20Cost estimation for sequential and index scans
  8. 12:25Why the planner chooses different plans
  9. 16:30Understanding range selectivity with histograms
  10. 18:35Improving planner accuracy with statistics
  11. 19:55Improving planner accuracy with CREATE STATISTICS
  12. 22:55Query planning checklist & final performance tuning tips
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.