## 72.2. Multivariate Statistics Examples

[72.2.1. Functional Dependencies](multivariate-statistics-examples.html#FUNCTIONAL-DEPENDENCIES)

[72.2.2. Multivariate N-Distinct Counts](multivariate-statistics-examples.html#MULTIVARIATE-NDISTINCT-COUNTS)

[72.2.3. MCV Lists](multivariate-statistics-examples.html#MCV-LISTS)

[]()

### 72.2.1. Functional Dependencies

 Multivariate correlation can be demonstrated with a very simple data set — a table with two columns, both containing the same values:

```
CREATE TABLE t (a INT, b INT);
INSERT INTO t SELECT i % 100, i % 100 FROM generate_series(1, 10000) s(i);
ANALYZE t;

```

 As explained in [Section 14.2](planner-stats.html), the planner can determine cardinality of `t` using the number of pages and rows obtained from `pg_class`:

```
SELECT relpages, reltuples FROM pg_class WHERE relname = 't';

 relpages | reltuples
### 72.2.2. Multivariate N-Distinct Counts

 A similar problem occurs with estimation of the cardinality of sets of multiple columns, such as the number of groups that would be generated by a `GROUP BY` clause. When `GROUP BY` lists a single column, the n-distinct estimate (which is visible as the estimated number of rows returned by the HashAggregate node) is very accurate:

```
EXPLAIN (ANALYZE, TIMING OFF) SELECT COUNT(*) FROM t GROUP BY a;
                                       QUERY PLAN                                        
### 72.2.3. MCV Lists

 As explained in [Section 72.2.1](multivariate-statistics-examples.html#FUNCTIONAL-DEPENDENCIES), functional dependencies are very cheap and efficient type of statistics, but their main limitation is their global nature (only tracking dependencies at the column level, not between individual column values).

 This section introduces multivariate variant of MCV (most-common values) lists, a straightforward extension of the per-column statistics described in [Section 72.1](row-estimation-examples.html). These statistics address the limitation by storing individual values, but it is naturally more expensive, both in terms of building the statistics in `ANALYZE`, storage and planning time.

 Let's look at the query from [Section 72.2.1](multivariate-statistics-examples.html#FUNCTIONAL-DEPENDENCIES) again, but this time with a MCV list created on the same set of columns (be sure to drop the functional dependencies, to make sure the planner uses the newly created statistics).

```
DROP STATISTICS stts;
CREATE STATISTICS stts2 (mcv) ON a, b FROM t;
ANALYZE t;
EXPLAIN (ANALYZE, TIMING OFF) SELECT * FROM t WHERE a = 1 AND b = 1;
                                   QUERY PLAN
