pg_statistic
pg_statistic#
The pg_statistic system catalog table stores statistical data about the contents of the database. Entries are created by ANALYZE and subsequently used by the query optimizer. There is one entry for each table column that has been analyzed. Note that all the statistical data is inherently approximate, even assuming that it is up-to-date.
pg_statistic also stores statistical data about the values of index expressions. These are described as if they were actual data columns; in particular, starelid references the index. No entry is made for an ordinary non-expression index column, however, since it would be redundant with the entry for the underlying table column.
Since different kinds of statistics may be appropriate for different kinds of data, pg_statistic is designed not to assume very much about what sort of statistics it stores. Only extremely general statistics (such as nullness) are given dedicated columns in pg_statistic. Everything else is stored in slots, which are groups of associated columns whose content is identified by a code number in one of the slot’s columns.
pg_statistic should not be readable by the public, since even statistical information about a table’s contents may be considered sensitive (for example: minimum and maximum values of a salary column). pg_stats is a publicly readable view on pg_statistic that only exposes information about those tables that are readable by the current user. See pg_stats, for more information on this view.
Table 1. pg_catalog.pg_statistic
column |
type |
references |
description |
|---|---|---|---|
|
oid |
pg_class_internal.oid |
The OID of root table. |
|
oid |
pg_class_internal.oid |
The table or index that the described column belongs to. |
|
smallint |
pg_attribute.attnum |
The number of the described column. |
|
real |
The fraction of the column’s entries that are null. |
|
|
integer |
The average stored width, in bytes, of nonnull entries. |
|
|
real |
The number of distinct nonnull data values in the column. A value greater than zero is the actual number of distinct values. A value less than zero is the negative of a fraction of the number of rows in the table (for example, a column in which values appear about twice on the average could be represented by |
|
|
smallint |
A code number indicating the kind of statistics stored in the |
|
|
smallint |
||
|
smallint |
||
|
smallint |
||
|
oid |
An operator used to derive the statistics stored in the |
|
|
oid |
||
|
oid |
||
|
oid |
||
|
real[] |
Numerical statistics of the appropriate kind for the |
|
|
real[] |
||
|
real[] |
||
|
real[] |
||
|
anyarray |
Column data values of the appropriate kind for the |
|
|
anyarray |
||
|
anyarray |
||
|
anyarray |