Conceptual
Login

Raise the Statistics Target on a Skewed Column

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?