↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

支持中的版本: 当前版本 (18) / 17 / 16 / 15 / 14
开发中的版本: 19 / 20devel
已结束支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2
历史版本。 PostgreSQL 9.2 已结束支持。 2017-11-09. 请参阅 当前版本手册.

45.42. pg_statistic #

目录pg_statistic存储有关数据库内容的统计数据。其中的项由ANALYZE创建,查询规划器会使用这些数据来进行查询规划。注意所有的统计数据天然就是近似的,即使它刚刚被更新。

通常,每个已分析的表列都有一个条目,其中stainherit = false。如果表具有继承子表,则还会创建第二个条目,其中stainherit = true。此行表示继承树上列的统计信息,即你可以通过SELECT column FROM table*看到的数据的统计信息,而stainherit = false行表示SELECT column FROM ONLY table的结果。

pg_statistic也存储关于索引表达式值的统计数据,就好像它们是真正的数据列,但在这种情况中starelid指索引。对一个普通非表达式索引列不会创建项,因为它将是底层表列的项的冗余。当前,索引表达式的项都具有stainherit = false。

由于不同种类的数据可能适合不同种类的统计信息,pg_statistic 在设计上尽量不对所存储的统计信息种类作出假定。只有极为通用的统计信息(例如空值情况)才在 pg_statistic 中有专用的列。其余统计信息都存储在“槽位”中。每个槽位都是一组相关的列,其内容由其中一列的代码编号来标识。更多信息见 src/include/catalog/pg_statistic.h。

pg_statistic不应公开可读,因为即使是表内容的统计信息也可能被认为是敏感的(例如,一个工资列的最大值和最小值就可能非常引人关注)。pg_stats是建立在pg_statistic之上的公开可读视图,它只会显示当前用户可读取的表的信息。

表 45.42. pg_statistic 列

NameTypeReferencesDescription
starelidoidpg_class.oidThe table or index that the described column belongs to
staattnumint2pg_attribute.attnumThe number of the described column
stainheritbool If true, the stats include inheritance child columns, not just the values in the specified relation
stanullfracfloat4 The fraction of the column's entries that are null
stawidthint4 The average stored width, in bytes, of nonnull entries
stadistinctfloat4 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.
stakindNint2  A code number indicating the kind of statistics stored in the Nth “slot” of the pg_statistic row.
staopNoidpg_operator.oid 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.
stanumbersNfloat4[]  Numerical statistics of the appropriate kind for the Nth “slot”, or null if the slot kind does not involve numerical values
stavaluesNanyarray  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, so there is no way to define these columns' type more specifically than anyarray.

报告文档问题

阅读 上游文档. 反馈更正前请先核对 当前版本手册.