PostgreSQL describes each column with a 100-bucket histogram and a list of its most common values, which is plenty for an evenly spread column and not enough for one where a few values cover most of the table. Raising default_statistics_target for that column with ALTER TABLE ... ALTER COLUMN ... SET STATISTICS, then running ANALYZE, gives the planner a finer picture and often flips a wrong plan. The cost is a slower ANALYZE and slightly more planning time, so you raise it per column, not globally.
Questions this Concept answers
Why does a skewed column benefit from a larger statistics target while an evenly spread column usually does not?
J
jeremy
Video
Tuning the PostgreSQL Statistics Target to Fix Selectivity Estimates for Spatial Indexes
A cost-based query planner estimates selectivity — the fraction of a relation a predicate is expected to match — from sampled column statistics, and the fidelity of those statistics bounds the qualit…