Glossary — in plain language

n_distinct

Also called: distinct estimate, stadistinct

In plain English

n_distinct is PostgreSQL’s estimate of how many different values a column holds. A positive number is a plain count; a negative number is a fraction of the table — for example -1 means every value is unique.

Why it matters

It drives grouping, join, and DISTINCT estimates. Because it is calculated from a small sample, it is often wrong on large high-cardinality columns, and a wrong n_distinct is one of the most common causes of a bad plan. You can override it by hand with ALTER TABLE ... ALTER COLUMN ... SET (n_distinct = ...).

Was this helpful?

← Browse the full glossary