バージョンごとのドキュメント一覧

53.51. pg_statistic #

The catalog <structname>pg_statistic</structname> stores statistical data about the contents of the database. Entries are created by <link linkend="sql-analyze"><command>ANALYZE</command></link> and subsequently used by the query planner. Note that all the statistical data is inherently approximate, even assuming that it is up-to-date. pg_statisticカタログはデータベースの内容に関する統計データを保存します。 項目はANALYZEで作成され、後に問い合わせプランナで使用されます。 最新のものと思ってもすべての統計データは本質的に大雑把なものであることに注意してください。

Normally there is one entry, with <structfield>stainherit</structfield> = <literal>false</literal>, for each table column that has been analyzed. If the table has inheritance children or partitions, a second entry with <structfield>stainherit</structfield> = <literal>true</literal> is also created. This row represents the column's statistics over the inheritance tree, i.e., statistics for the data you'd see with <literal>SELECT <replaceable>column</replaceable> FROM <replaceable>table</replaceable>*</literal>, whereas the <structfield>stainherit</structfield> = <literal>false</literal> row represents the results of <literal>SELECT <replaceable>column</replaceable> FROM ONLY <replaceable>table</replaceable></literal>. 通常は、解析されるテーブル列毎に、stainherit = falseを持つ1つの項目が存在します。 テーブルが継承された子あるいはパーティションを持つ場合、stainherit = trueを持つ2つ目の項目が作成されます。 この行は継承ツリー全体に渡る列の統計情報、つまり、SELECT column FROM table*で確認できるデータに対する統計情報を表します。 一方でstainherit = falseの行はSELECT column FROM ONLY tableの結果を表します。

<structname>pg_statistic</structname> also stores statistical data about the values of index expressions. These are described as if they were actual data columns; in particular, <structfield>starelid</structfield> 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 <structfield>stainherit</structfield> = <literal>false</literal>. pg_statisticはインデックス式の値についての統計データも格納します。 これらはあたかも値が実際のデータ列であるかのように表現されます。 特にstarelidはインデックスを参照します。 これは元のテーブル列の項目に対して冗長となるので、普通の式を持たないインデックス列では項目は作成されません。 現在インデックス式用の項目は常にstainherit = falseを持ちます。

Since different kinds of statistics might be appropriate for different kinds of data, <structname>pg_statistic</structname> 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 <structname>pg_statistic</structname>. Everything else is stored in <quote>slots</quote>, 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 <filename>src/include/catalog/pg_statistic.h</filename>. 異なる種類のデータに対しては違った種類の統計が相応しいことからpg_statisticはどのような情報を保存するか深く推定しないように設計されています。 (例えばNULLであるような)極端に一般的な統計のみpg_statisticの特定の列に入ります。 その他すべてはスロット列の内の1つのコード番号でその内容が識別される相関している列のグループであるスロットに保存されます。 src/include/catalog/pg_statistic.hを参照してください。

<structname>pg_statistic</structname> 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.) <link linkend="view-pg-stats"><structname>pg_stats</structname></link> is a publicly readable view on <structname>pg_statistic</structname> that only exposes information about those tables that are readable by the current user. pg_statisticはテーブル内容に関する統計情報と言えども秘密の情報とみなされますので、一般のユーザが読み取り可能であってはいけません。 (給与列の最高額と最低額などは誰もが興味をそそられる良い例ですよね。) pg_statsは一般のユーザが読み取り可能なpg_statisticに対するビューで、既存のユーザが読んでも差し支えないテーブルの情報のみを開示しています。

表53.51 pg_statisticの列

<title><structname>pg_statistic</structname> Columns</title>

Column Type 列 型

Description 説明

starelid oid (references <link linkend="catalog-pg-class"><structname>pg_class</structname></link>.<structfield>oid</structfield>) (参照先 pg_class.oid

The table or index that the described column belongs to 記述された列が属するテーブルもしくはインデックス

staattnum int2 (references <link linkend="catalog-pg-attribute"><structname>pg_attribute</structname></link>.<structfield>attnum</structfield>) (参照先 pg_attribute.attnum

The number of the described column 記述された列数

stainherit bool

If true, the stats include values from child tables, not just the values in the specified relation trueの場合、統計情報には指定されたリレーションの値だけではなく、子テーブルの値も含まれます

stanullfrac float4

The fraction of the column's entries that are null NULL値である列項目の割合

stawidth int4

The average stored width, in bytes, of nonnull entries 非NULL項目の平均保存幅(バイト単位)

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 <structfield>stadistinct</structfield> = -0.4. A zero value means the number of distinct values is unknown. 列内で非NULL個別値を持つデータ数。 ゼロより大きい値は実際の個別値の数です。 ゼロより小さい値はテーブル内の行数に対する乗数を負にしたものです。 例えば、約80%の値が非NULLで、それぞれの非NULL値が平均して2回ほど出現する列はstadistinct = -0.4であると表現されます。 ゼロは個別値の数を特定できない場合です。

stakindN int2

A code number indicating the kind of statistics stored in the <replaceable>N</replaceable>th <quote>slot</quote> of the <structname>pg_statistic</structname> row. pg_statistic行のN番目のスロットに保存されている統計情報の種類を示すコード番号。

staopN oid (references <link linkend="catalog-pg-operator"><structname>pg_operator</structname></link>.<structfield>oid</structfield>) (参照先 pg_operator.oid

An operator used to derive the statistics stored in the <replaceable>N</replaceable>th <quote>slot</quote>. For example, a histogram slot would show the <literal>&lt;</literal> operator that defines the sort order of the data. Zero if the statistics kind does not require an operator. N番目のスロットに保存されている統計情報を引き出すために使われる演算子。 例えば、ヒストグラムスロットはデータの並べ替えの順序を定義する<演算子を示します。 統計情報が演算子を要求しない種類であればゼロです。

stacollN oid (references <link linkend="catalog-pg-collation"><structname>pg_collation</structname></link>.<structfield>oid</structfield>) (参照先 pg_collation.oid

The collation used to derive the statistics stored in the <replaceable>N</replaceable>th <quote>slot</quote>. 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. N番目のスロットに格納された統計情報を派生させるために使われる照合順序。 たとえば、照合可能な列のヒストグラムスロットはそのデータをソート順を定義する照合順を表示します。 ゼロなら照合可能ではないデータです。

stanumbersN float4[]

Numerical statistics of the appropriate kind for the <replaceable>N</replaceable>th <quote>slot</quote>, or null if the slot kind does not involve numerical values N番目のスロットに対する適切な種類の数値統計情報、もしくはスロットの種類に数値が含まれない時はNULLです。

stavaluesN anyarray

Column data values of the appropriate kind for the <replaceable>N</replaceable>th <quote>slot</quote>, 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 <type>anyarray</type>. N番目のスロットに対する適切な種類の列データの値、もしくはスロットの種類にデータ値が何も保存されていない場合はNULL。 それぞれの配列要素の値は実際には特定された列のデータ型、もしくは配列要素の型といったような関連のある型になります。ですからanyarrayとする以外に列型を定義することはできません。