选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

受支持版本: 当前版本 (18) / 17 / 16 / 15 / 14
测试与开发版本: 19 / devel
不受支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0
历史版本PostgreSQL 9.2 已于 2017 年 11 月结束社区维护,本页译文保留供仍在使用旧版本的读者参考。新系统请看当前版本

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

Name Type References Description
starelid oid pg_class.oid The table or index that the described column belongs to
staattnum int2 pg_attribute.attnum The number of the described column
stainherit bool   If true, the stats include inheritance child columns, not just the values in the specified relation
stanullfrac float4   The fraction of the column's entries that are null
stawidth int4   The average stored width, in bytes, of nonnull entries
stadistinct 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.
stakindN int2   A code number indicating the kind of statistics stored in the Nth slot of the pg_statistic row.
staopN oid pg_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.
stanumbersN float4[]   Numerical statistics of the appropriate kind for the Nth slot, or null if the slot kind does not involve numerical values
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, so there is no way to define these columns' type more specifically than anyarray.

提交更正

译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。 英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。