Postgres Extended Statistics

Back

Refer to my blog here for a much detailed example

Types of statistics

Functional Dependencies

This is used when there is correlation between two or more columns

CREATE STATISTICS stts (dependencies) ON a, b FROM t;

Multivariate N-Distinct Counts

This is used when multiple columns would be used along mith GROUP BY clause. When GROUP BY lists a single column, the n-distinct is accurate

CREATE STATISTICS stts (dependencies, ndistinct) ON a, b FROM t;

MCV Lists

MCV (most-common values) lists. This creates all combinations and addresses storing individual values, bit it is more expensive

CREATE STATISTICS stts2 (mcv) ON a, b FROM t;