PostgreSQL 15 ← 14
SYSTEM CATALOG · 系统目录
pg_statistic
The catalog pg_statistic stores statistical data about the contents of the database. Entries are created by ANALYZE and subsequently used by the query planner. Note that all the statistical data is inherently approximate, even assuming that it is up-to-date. Normally there is one entry, with stainherit = false, for each table column that has been analyzed. If the table has inheritance children or partitions, a second entry with stainherit = true is also created. This row represents the column's statistics over the inheritance tree, i.e., statistics for the data you'd see with SELECT column FROM table*, whereas the stainherit = false row represents the results of SELECT column FROM ONLY table. 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. Currently, entries for index expressions always have stainherit = false. Since different kinds of statistics might 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. For more information see src/include/catalog/pg_statistic.h. pg_statistic should not be readable by the public, since even statistical information about a table's contents might be considered sensitive. (Example: minimum and maximum values of a salary column might be quite interesting.) pg_stats is a publicly readable view on pg_statistic that only exposes information about those tables that are readable by the current user.
已与 PostgreSQL 18.6 实例逐字段核对 · 原始实测记录 ↗
字段结构 PostgreSQL 18
pg_statistic| 字段 / COLUMN | 类型 / TYPE | 说明 / DESCRIPTION |
|---|---|---|
starelid |
oidNOT NULL |
The table or index that the described column belongs to引用:pg_class.oid |
staattnum |
smallintNOT NULL文档原写法:int2 |
The number of the described column引用:pg_attribute.attnum |
stainherit |
booleanNOT NULL文档原写法:bool |
If true, the stats include values from child tables, not just the values in the specified relation |
stanullfrac |
realNOT NULL文档原写法:float4 |
The fraction of the column's entries that are null |
stawidth |
integerNOT NULL文档原写法:int4 |
The average stored width, in bytes, of nonnull entries |
stadistinct |
realNOT NULL文档原写法:float4 |
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 multiplier for the number of rows in the table; for example, a column in which about 80% of the values are nonnull and each nonnull value appears about twice on average could be represented by stadistinct = -0.4. A zero value means the number of distinct values is unknown. |
stakind1文档名称:stakindN |
smallintNOT NULL文档原写法:int2 |
A code number indicating the kind of statistics stored in the Nth “slot” of the pg_statistic row.Expanded documentation slot placeholder using the version-specific catalog header. |
stakind2文档名称:stakindN |
smallintNOT NULL文档原写法:int2 |
A code number indicating the kind of statistics stored in the Nth “slot” of the pg_statistic row.Expanded documentation slot placeholder using the version-specific catalog header. |
stakind3文档名称:stakindN |
smallintNOT NULL文档原写法:int2 |
A code number indicating the kind of statistics stored in the Nth “slot” of the pg_statistic row.Expanded documentation slot placeholder using the version-specific catalog header. |
stakind4文档名称:stakindN |
smallintNOT NULL文档原写法:int2 |
A code number indicating the kind of statistics stored in the Nth “slot” of the pg_statistic row.Expanded documentation slot placeholder using the version-specific catalog header. |
stakind5文档名称:stakindN |
smallintNOT NULL文档原写法:int2 |
A code number indicating the kind of statistics stored in the Nth “slot” of the pg_statistic row.Expanded documentation slot placeholder using the version-specific catalog header. |
staop1文档名称:staopN |
oidNOT NULL |
An operator used to derive the statistics stored in the Nth “slot”. For example, a histogram slot would show the < operator that defines the sort order of the data. Zero if the statistics kind does not require an operator.引用:pg_operator.oidExpanded documentation slot placeholder using the version-specific catalog header. |
staop2文档名称:staopN |
oidNOT NULL |
An operator used to derive the statistics stored in the Nth “slot”. For example, a histogram slot would show the < operator that defines the sort order of the data. Zero if the statistics kind does not require an operator.引用:pg_operator.oidExpanded documentation slot placeholder using the version-specific catalog header. |
staop3文档名称:staopN |
oidNOT NULL |
An operator used to derive the statistics stored in the Nth “slot”. For example, a histogram slot would show the < operator that defines the sort order of the data. Zero if the statistics kind does not require an operator.引用:pg_operator.oidExpanded documentation slot placeholder using the version-specific catalog header. |
staop4文档名称:staopN |
oidNOT NULL |
An operator used to derive the statistics stored in the Nth “slot”. For example, a histogram slot would show the < operator that defines the sort order of the data. Zero if the statistics kind does not require an operator.引用:pg_operator.oidExpanded documentation slot placeholder using the version-specific catalog header. |
staop5文档名称:staopN |
oidNOT NULL |
An operator used to derive the statistics stored in the Nth “slot”. For example, a histogram slot would show the < operator that defines the sort order of the data. Zero if the statistics kind does not require an operator.引用:pg_operator.oidExpanded documentation slot placeholder using the version-specific catalog header. |
stacoll1文档名称:stacollN |
oidNOT NULL |
The collation used to derive the statistics stored in the Nth “slot”. For example, a histogram slot for a collatable column would show the collation that defines the sort order of the data. Zero for noncollatable data.引用:pg_collation.oidExpanded documentation slot placeholder using the version-specific catalog header. |
stacoll2文档名称:stacollN |
oidNOT NULL |
The collation used to derive the statistics stored in the Nth “slot”. For example, a histogram slot for a collatable column would show the collation that defines the sort order of the data. Zero for noncollatable data.引用:pg_collation.oidExpanded documentation slot placeholder using the version-specific catalog header. |
stacoll3文档名称:stacollN |
oidNOT NULL |
The collation used to derive the statistics stored in the Nth “slot”. For example, a histogram slot for a collatable column would show the collation that defines the sort order of the data. Zero for noncollatable data.引用:pg_collation.oidExpanded documentation slot placeholder using the version-specific catalog header. |
stacoll4文档名称:stacollN |
oidNOT NULL |
The collation used to derive the statistics stored in the Nth “slot”. For example, a histogram slot for a collatable column would show the collation that defines the sort order of the data. Zero for noncollatable data.引用:pg_collation.oidExpanded documentation slot placeholder using the version-specific catalog header. |
stacoll5文档名称:stacollN |
oidNOT NULL |
The collation used to derive the statistics stored in the Nth “slot”. For example, a histogram slot for a collatable column would show the collation that defines the sort order of the data. Zero for noncollatable data.引用:pg_collation.oidExpanded documentation slot placeholder using the version-specific catalog header. |
stanumbers1文档名称:stanumbersN |
real[]文档原写法:float4[] |
Numerical statistics of the appropriate kind for the Nth “slot”, or null if the slot kind does not involve numerical valuesExpanded documentation slot placeholder using the version-specific catalog header. |
stanumbers2文档名称:stanumbersN |
real[]文档原写法:float4[] |
Numerical statistics of the appropriate kind for the Nth “slot”, or null if the slot kind does not involve numerical valuesExpanded documentation slot placeholder using the version-specific catalog header. |
stanumbers3文档名称:stanumbersN |
real[]文档原写法:float4[] |
Numerical statistics of the appropriate kind for the Nth “slot”, or null if the slot kind does not involve numerical valuesExpanded documentation slot placeholder using the version-specific catalog header. |
stanumbers4文档名称:stanumbersN |
real[]文档原写法:float4[] |
Numerical statistics of the appropriate kind for the Nth “slot”, or null if the slot kind does not involve numerical valuesExpanded documentation slot placeholder using the version-specific catalog header. |
stanumbers5文档名称:stanumbersN |
real[]文档原写法:float4[] |
Numerical statistics of the appropriate kind for the Nth “slot”, or null if the slot kind does not involve numerical valuesExpanded documentation slot placeholder using the version-specific catalog header. |
stavalues1文档名称:stavaluesN |
anyarray |
Column data values of the appropriate kind for the Nth “slot”, or null if the slot kind does not store any data values. Each array's element values are actually of the specific column's data type, or a related type such as an array's element type, so there is no way to define these columns' type more specifically than anyarray.Expanded documentation slot placeholder using the version-specific catalog header. |
stavalues2文档名称:stavaluesN |
anyarray |
Column data values of the appropriate kind for the Nth “slot”, or null if the slot kind does not store any data values. Each array's element values are actually of the specific column's data type, or a related type such as an array's element type, so there is no way to define these columns' type more specifically than anyarray.Expanded documentation slot placeholder using the version-specific catalog header. |
stavalues3文档名称:stavaluesN |
anyarray |
Column data values of the appropriate kind for the Nth “slot”, or null if the slot kind does not store any data values. Each array's element values are actually of the specific column's data type, or a related type such as an array's element type, so there is no way to define these columns' type more specifically than anyarray.Expanded documentation slot placeholder using the version-specific catalog header. |
stavalues4文档名称:stavaluesN |
anyarray |
Column data values of the appropriate kind for the Nth “slot”, or null if the slot kind does not store any data values. Each array's element values are actually of the specific column's data type, or a related type such as an array's element type, so there is no way to define these columns' type more specifically than anyarray.Expanded documentation slot placeholder using the version-specific catalog header. |
stavalues5文档名称:stavaluesN |
anyarray |
Column data values of the appropriate kind for the Nth “slot”, or null if the slot kind does not store any data values. Each array's element values are actually of the specific column's data type, or a related type such as an array's element type, so there is no way to define these columns' type more specifically than anyarray.Expanded documentation slot placeholder using the version-specific catalog header. |
标记“隐式列”的字段不包含在 SELECT * 中;部分早期统计视图由同版本源码补全,额外来源会显示在字段说明中。
通用系统列 6
PostgreSQL 提供的系统属性,通常不在 SELECT * 中展开。单独保留,不与普通字段混算。
| 字段 | 类型 | attnum |
|---|---|---|
tableoid | oid | -6 |
cmax | cid | -5 |
xmax | xid | -4 |
cmin | cid | -3 |
xmin | xid | -2 |
ctid | tid | -1 |
字段演化矩阵
悬停查看字段类型9.0 是收录基线;基线中已存在的字段不标记为新增。矩阵按字段名称对齐,重命名显示为旧字段移除与新字段新增。
演化时间线
相邻大版本的变化PostgreSQL 14 ← 13
PostgreSQL 12 ← 11
PostgreSQL 10 ← 9.6
PostgreSQL 9.2 ← 9.1
PostgreSQL 9.1 ← 9.0
比较任意两个版本
选择两个版本,查看字段的新增、移除与类型变化。交互比较需要 JavaScript;演化时间线可直接阅读。